user_urls_list.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <!-- User URLs List Component -->
  2. {% if user_urls %}
  3. <div class="max-w-4xl mx-auto">
  4. <div class="bg-white rounded-2xl shadow-sm border border-gray-100 p-8">
  5. <h2 class="text-xl font-semibold text-gray-900 mb-6">
  6. Tus enlaces <span class="text-gray-500 text-base font-normal">({{ user_urls|length }})</span>
  7. </h2>
  8. <div class="space-y-3">
  9. {% for url in user_urls %}
  10. <div class="border border-gray-100 rounded-xl p-4 hover:bg-gray-50 transition-colors duration-200">
  11. <div class="flex items-center justify-between">
  12. <div class="flex-1 min-w-0">
  13. <div class="flex items-center space-x-3 mb-2">
  14. <code class="text-sm bg-gray-100 text-primary px-3 py-1 rounded-lg font-mono">{{ url[1] }}</code>
  15. <button
  16. onclick="copyToClipboard('https://please.checkthis.space/s/{{ url[1] }}')"
  17. class="text-gray-400 hover:text-primary transition-colors duration-200"
  18. title="Copiar enlace"
  19. >
  20. <i class="fas fa-copy text-sm"></i>
  21. </button>
  22. <span class="text-xs text-gray-500">{{ url[3] }} clicks</span>
  23. {% if url[4] %}
  24. {% set expires_date = url[4][:19] %}
  25. <span class="text-xs px-2 py-1 rounded-full bg-orange-100 text-orange-600">
  26. <i class="fas fa-clock mr-1"></i>Expira: {{ expires_date.replace('T', ' ') }}
  27. </span>
  28. {% else %}
  29. <span class="text-xs px-2 py-1 rounded-full bg-green-100 text-green-600">
  30. <i class="fas fa-infinity mr-1"></i>Permanente
  31. </span>
  32. {% endif %}
  33. </div>
  34. <p class="text-sm text-gray-600 truncate" title="{{ url[0] }}">
  35. {{ url[0] }}
  36. </p>
  37. </div>
  38. <div class="flex items-center space-x-2 ml-4">
  39. <a
  40. href="/s/{{ url[1] }}"
  41. target="_blank"
  42. class="text-gray-400 hover:text-primary transition-colors duration-200"
  43. title="Visitar enlace"
  44. >
  45. <i class="fas fa-external-link-alt text-sm"></i>
  46. </a>
  47. <button
  48. onclick="showDeleteModal('{{ url[1] }}')"
  49. class="text-gray-400 hover:text-red-500 transition-colors duration-200"
  50. title="Eliminar enlace"
  51. >
  52. <i class="fas fa-trash text-sm"></i>
  53. </button>
  54. </div>
  55. </div>
  56. </div>
  57. {% endfor %}
  58. </div>
  59. </div>
  60. </div>
  61. {% else %}
  62. <div class="max-w-2xl mx-auto text-center">
  63. <div class="bg-white rounded-2xl shadow-sm border border-gray-100 p-12">
  64. <div class="w-16 h-16 bg-gray-100 rounded-full flex items-center justify-center mx-auto mb-4">
  65. <i class="fas fa-link text-2xl text-gray-400"></i>
  66. </div>
  67. <h3 class="text-lg font-medium text-gray-700 mb-2">No hay enlaces aún</h3>
  68. <p class="text-gray-500">Acorta tu primer enlace arriba</p>
  69. </div>
  70. </div>
  71. {% endif %}
  72. <!-- Modal de confirmación de eliminación -->
  73. <div id="deleteModal" class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full hidden z-50">
  74. <div class="relative top-20 mx-auto p-5 border w-96 shadow-lg rounded-md bg-white">
  75. <div class="mt-3 text-center">
  76. <div class="mx-auto flex items-center justify-center h-12 w-12 rounded-full bg-red-100">
  77. <i class="fas fa-exclamation-triangle text-red-600 text-xl"></i>
  78. </div>
  79. <h3 class="text-lg leading-6 font-medium text-gray-900 mt-4">Eliminar enlace</h3>
  80. <div class="mt-2 px-7 py-3">
  81. <p class="text-sm text-gray-500">
  82. ¿Estás seguro de que quieres eliminar este enlace? Esta acción no se puede deshacer.
  83. </p>
  84. </div>
  85. <div class="items-center px-4 py-3">
  86. <button
  87. id="confirmDelete"
  88. class="px-4 py-2 bg-red-500 text-white text-base font-medium rounded-md w-24 mr-2 hover:bg-red-600 focus:outline-none focus:ring-2 focus:ring-red-300"
  89. >
  90. Eliminar
  91. </button>
  92. <button
  93. id="cancelDelete"
  94. class="px-4 py-2 bg-gray-300 text-gray-800 text-base font-medium rounded-md w-24 hover:bg-gray-400 focus:outline-none focus:ring-2 focus:ring-gray-300"
  95. >
  96. Cancelar
  97. </button>
  98. </div>
  99. </div>
  100. </div>
  101. </div>
  102. <script>
  103. let currentShortCode = null;
  104. // Mostrar modal de confirmación
  105. function showDeleteModal(shortCode) {
  106. currentShortCode = shortCode;
  107. document.getElementById('deleteModal').classList.remove('hidden');
  108. }
  109. // Ocultar modal de confirmación
  110. function hideDeleteModal() {
  111. document.getElementById('deleteModal').classList.add('hidden');
  112. currentShortCode = null;
  113. }
  114. // Event listeners para el modal
  115. document.getElementById('confirmDelete').addEventListener('click', function() {
  116. if (currentShortCode) {
  117. deleteUrl(currentShortCode);
  118. hideDeleteModal();
  119. }
  120. });
  121. document.getElementById('cancelDelete').addEventListener('click', hideDeleteModal);
  122. // Cerrar modal al hacer clic fuera de él
  123. document.getElementById('deleteModal').addEventListener('click', function(e) {
  124. if (e.target === this) {
  125. hideDeleteModal();
  126. }
  127. });
  128. // Delete URL function
  129. async function deleteUrl(shortCode) {
  130. try {
  131. const response = await fetch(`/delete/${shortCode}`, {
  132. method: 'POST'
  133. });
  134. const data = await response.json();
  135. if (data.success) {
  136. showToast('Enlace eliminado exitosamente', 'success');
  137. // Reload page to update the list
  138. setTimeout(() => {
  139. window.location.reload();
  140. }, 1000);
  141. } else {
  142. showToast(data.error || 'Error al eliminar el enlace', 'error');
  143. }
  144. } catch (error) {
  145. showToast('Error de conexión', 'error');
  146. }
  147. }
  148. </script>