favorites.blade.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. @extends('layouts.app')
  2. @section('title', 'Избранное — Точка')
  3. @section('content')
  4. <section class="page-hdr">
  5. <div class="container">
  6. <div class="sh-label reveal-up">Сохранённые автомобили</div>
  7. <h1 class="reveal">ИЗБРАННОЕ</h1>
  8. <nav class="breadcrumb">
  9. <a href="{{ route('home') }}">Главная</a>
  10. <span>/</span>
  11. <span>Избранное</span>
  12. </nav>
  13. </div>
  14. </section>
  15. <section class="section sec-alt" style="padding-top:32px">
  16. <div class="container">
  17. {{-- Top-bar --}}
  18. <div class="cat-top" id="favTopBar" style="display:none">
  19. <div class="cat-count">В избранном: <strong id="favCount">0</strong> авт.</div>
  20. <button onclick="clearFavorites()" class="btn btn-outline" style="font-size:13px;padding:8px 18px">
  21. ✕ Очистить всё
  22. </button>
  23. </div>
  24. {{-- Пустое состояние (показывается пока загружается или когда пусто) --}}
  25. <div id="favEmpty" class="no-results" style="padding:80px 20px;text-align:center">
  26. <div class="nr-i">♡</div>
  27. <h3>Избранное пусто</h3>
  28. <p>Нажмите ♡ на карточке автомобиля, чтобы добавить его сюда</p>
  29. <a href="{{ route('catalog') }}" class="btn btn-primary" style="margin-top:20px">Перейти в каталог</a>
  30. </div>
  31. {{-- Сетка карточек --}}
  32. <div class="cars-grid" id="favGrid" style="display:none"></div>
  33. </div>
  34. </section>
  35. @endsection
  36. @push('scripts')
  37. <script>
  38. (function () {
  39. var grid = document.getElementById('favGrid');
  40. var empty = document.getElementById('favEmpty');
  41. var topBar = document.getElementById('favTopBar');
  42. var counter = document.getElementById('favCount');
  43. function getIds() {
  44. try { return JSON.parse(localStorage.getItem('tocha_favorites') || '[]'); }
  45. catch (e) { return []; }
  46. }
  47. function load() {
  48. var ids = getIds();
  49. if (!ids.length) { showEmpty(); return; }
  50. fetch('{{ route('favorites.load') }}', {
  51. method: 'POST',
  52. headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
  53. body: JSON.stringify({ ids: ids })
  54. })
  55. .then(function(r){ return r.json(); })
  56. .then(function(data) {
  57. if (!data.count) { showEmpty(); return; }
  58. grid.innerHTML = data.html;
  59. grid.style.display = '';
  60. empty.style.display= 'none';
  61. topBar.style.display = '';
  62. counter.textContent = data.count;
  63. // Подсвечиваем сердца на подгруженных карточках
  64. markHearts();
  65. });
  66. }
  67. function showEmpty() {
  68. grid.style.display = 'none';
  69. topBar.style.display = 'none';
  70. empty.style.display = '';
  71. }
  72. window.clearFavorites = function () {
  73. if (!confirm('Очистить список избранного?')) return;
  74. localStorage.removeItem('tocha_favorites');
  75. updateNavCounter();
  76. showEmpty();
  77. };
  78. load();
  79. })();
  80. </script>
  81. @endpush