work on the frontend
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
<nav class="bg-white border-b border-gray-200 sticky top-0 z-50" x-data="{ mobileMenuOpen: false, userMenuOpen: false }">
|
||||
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||
<div class="flex justify-between h-16">
|
||||
<!-- Logo and Primary Navigation -->
|
||||
<div class="flex">
|
||||
<!-- Logo -->
|
||||
<div class="flex-shrink-0 flex items-center">
|
||||
<a href="{{ route('products.index') }}" class="flex items-center space-x-2">
|
||||
<svg class="h-8 w-8 text-primary-600" fill="currentColor" viewBox="0 0 24 24">
|
||||
<path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"></path>
|
||||
</svg>
|
||||
<span class="text-xl font-bold text-gray-900">{{ config('app.name', 'BestTech') }}</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Desktop Navigation -->
|
||||
<div class="hidden sm:ml-8 sm:flex sm:space-x-8">
|
||||
<a href="{{ route('products.index') }}"
|
||||
class="inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium {{ request()->routeIs('products.index') ? 'border-primary-500 text-gray-900' : 'border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700' }}">
|
||||
Discover
|
||||
</a>
|
||||
@auth
|
||||
@if(auth()->user()->hasAnyRole(['admin', 'moderator']))
|
||||
<a href="{{ route('products.manage') }}"
|
||||
class="inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium {{ request()->routeIs('products.manage') ? 'border-primary-500 text-gray-900' : 'border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700' }}">
|
||||
Manage
|
||||
</a>
|
||||
@endif
|
||||
@endauth
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Right Side -->
|
||||
<div class="hidden sm:ml-6 sm:flex sm:items-center sm:space-x-4">
|
||||
@guest
|
||||
<a href="{{ route('login') }}" class="text-gray-700 hover:text-gray-900 px-3 py-2 rounded-md text-sm font-medium">
|
||||
Sign in
|
||||
</a>
|
||||
<a href="{{ route('register') }}" class="btn-primary">
|
||||
Get started
|
||||
</a>
|
||||
@else
|
||||
<!-- Submit Product Button -->
|
||||
<a href="{{ route('products.create') }}" class="btn-primary flex items-center space-x-2">
|
||||
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path>
|
||||
</svg>
|
||||
<span>Submit</span>
|
||||
</a>
|
||||
|
||||
<!-- User Menu Dropdown -->
|
||||
<div class="relative" @click.away="userMenuOpen = false">
|
||||
<button @click="userMenuOpen = !userMenuOpen"
|
||||
class="flex items-center space-x-3 text-sm rounded-full focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500">
|
||||
<div class="h-8 w-8 rounded-full bg-gradient-to-br from-primary-500 to-accent-500 flex items-center justify-center text-white font-semibold">
|
||||
{{ strtoupper(substr(Auth::user()->name, 0, 1)) }}
|
||||
</div>
|
||||
<svg class="h-5 w-5 text-gray-400" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path>
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<!-- Dropdown Menu -->
|
||||
<div x-show="userMenuOpen"
|
||||
x-transition:enter="transition ease-out duration-100"
|
||||
x-transition:enter-start="transform opacity-0 scale-95"
|
||||
x-transition:enter-end="transform opacity-100 scale-100"
|
||||
x-transition:leave="transition ease-in duration-75"
|
||||
x-transition:leave-start="transform opacity-100 scale-100"
|
||||
x-transition:leave-end="transform opacity-0 scale-95"
|
||||
class="origin-top-right absolute right-0 mt-2 w-48 rounded-lg shadow-lg py-1 bg-white ring-1 ring-black ring-opacity-5"
|
||||
style="display: none;">
|
||||
<div class="px-4 py-2 border-b border-gray-100">
|
||||
<p class="text-sm font-medium text-gray-900">{{ Auth::user()->name }}</p>
|
||||
<p class="text-xs text-gray-500">{{ Auth::user()->email }}</p>
|
||||
</div>
|
||||
<a href="{{ route('profile.show', Auth::user()) }}" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
|
||||
Your Profile
|
||||
</a>
|
||||
<a href="{{ route('profile.edit') }}" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
|
||||
Settings
|
||||
</a>
|
||||
<form method="POST" action="{{ route('logout') }}">
|
||||
@csrf
|
||||
<button type="submit" class="block w-full text-left px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
|
||||
Sign out
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@endguest
|
||||
</div>
|
||||
|
||||
<!-- Mobile menu button -->
|
||||
<div class="flex items-center sm:hidden">
|
||||
<button @click="mobileMenuOpen = !mobileMenuOpen"
|
||||
class="inline-flex items-center justify-center p-2 rounded-md text-gray-400 hover:text-gray-500 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-primary-500">
|
||||
<svg class="h-6 w-6" :class="{'hidden': mobileMenuOpen, 'block': !mobileMenuOpen }" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path>
|
||||
</svg>
|
||||
<svg class="h-6 w-6" :class="{'block': mobileMenuOpen, 'hidden': !mobileMenuOpen }" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Mobile menu -->
|
||||
<div x-show="mobileMenuOpen"
|
||||
x-transition:enter="transition ease-out duration-100"
|
||||
x-transition:enter-start="transform opacity-0 scale-95"
|
||||
x-transition:enter-end="transform opacity-100 scale-100"
|
||||
x-transition:leave="transition ease-in duration-75"
|
||||
x-transition:leave-start="transform opacity-100 scale-100"
|
||||
x-transition:leave-end="transform opacity-0 scale-95"
|
||||
class="sm:hidden"
|
||||
style="display: none;">
|
||||
<div class="pt-2 pb-3 space-y-1">
|
||||
<a href="{{ route('products.index') }}"
|
||||
class="block pl-3 pr-4 py-2 border-l-4 text-base font-medium {{ request()->routeIs('products.index') ? 'border-primary-500 text-primary-700 bg-primary-50' : 'border-transparent text-gray-500 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-700' }}">
|
||||
Discover
|
||||
</a>
|
||||
@auth
|
||||
@if(auth()->user()->hasAnyRole(['admin', 'moderator']))
|
||||
<a href="{{ route('products.manage') }}"
|
||||
class="block pl-3 pr-4 py-2 border-l-4 text-base font-medium {{ request()->routeIs('products.manage') ? 'border-primary-500 text-primary-700 bg-primary-50' : 'border-transparent text-gray-500 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-700' }}">
|
||||
Manage
|
||||
</a>
|
||||
@endif
|
||||
@endauth
|
||||
</div>
|
||||
@auth
|
||||
<div class="pt-4 pb-3 border-t border-gray-200">
|
||||
<div class="flex items-center px-4">
|
||||
<div class="flex-shrink-0">
|
||||
<div class="h-10 w-10 rounded-full bg-gradient-to-br from-primary-500 to-accent-500 flex items-center justify-center text-white font-semibold">
|
||||
{{ strtoupper(substr(Auth::user()->name, 0, 1)) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="ml-3">
|
||||
<div class="text-base font-medium text-gray-800">{{ Auth::user()->name }}</div>
|
||||
<div class="text-sm font-medium text-gray-500">{{ Auth::user()->email }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-3 space-y-1">
|
||||
<a href="{{ route('products.create') }}" class="block px-4 py-2 text-base font-medium text-gray-500 hover:text-gray-800 hover:bg-gray-100">
|
||||
Submit Product
|
||||
</a>
|
||||
<a href="{{ route('profile.show', Auth::user()) }}" class="block px-4 py-2 text-base font-medium text-gray-500 hover:text-gray-800 hover:bg-gray-100">
|
||||
Your Profile
|
||||
</a>
|
||||
<a href="{{ route('profile.edit') }}" class="block px-4 py-2 text-base font-medium text-gray-500 hover:text-gray-800 hover:bg-gray-100">
|
||||
Settings
|
||||
</a>
|
||||
<form method="POST" action="{{ route('logout') }}">
|
||||
@csrf
|
||||
<button type="submit" class="block w-full text-left px-4 py-2 text-base font-medium text-gray-500 hover:text-gray-800 hover:bg-gray-100">
|
||||
Sign out
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@else
|
||||
<div class="pt-4 pb-3 border-t border-gray-200 space-y-1">
|
||||
<a href="{{ route('login') }}" class="block px-4 py-2 text-base font-medium text-gray-500 hover:text-gray-800 hover:bg-gray-100">
|
||||
Sign in
|
||||
</a>
|
||||
<a href="{{ route('register') }}" class="block px-4 py-2 text-base font-medium text-primary-600 hover:text-primary-800 hover:bg-gray-100">
|
||||
Get started
|
||||
</a>
|
||||
</div>
|
||||
@endguest
|
||||
</div>
|
||||
</nav>
|
||||
@@ -0,0 +1,46 @@
|
||||
@props(['product'])
|
||||
|
||||
@php
|
||||
$isBookmarked = auth()->check() && $product->isBookmarkedBy(auth()->user());
|
||||
@endphp
|
||||
|
||||
<div x-data="{
|
||||
bookmarked: {{ $isBookmarked ? 'true' : 'false' }},
|
||||
loading: false,
|
||||
toggleBookmark() {
|
||||
if (this.loading) return;
|
||||
this.loading = true;
|
||||
|
||||
fetch('{{ route('products.bookmark', $product) }}', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}',
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
this.bookmarked = data.bookmarked;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
})
|
||||
.finally(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
}">
|
||||
<button @click="toggleBookmark()"
|
||||
:disabled="loading"
|
||||
:title="bookmarked ? 'Remove bookmark' : 'Bookmark this product'"
|
||||
class="text-gray-400 hover:text-primary-600 transition-colors disabled:opacity-50">
|
||||
<svg class="h-5 w-5"
|
||||
:class="{ 'animate-pulse': loading }"
|
||||
:fill="bookmarked ? 'currentColor' : 'none'"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 5a2 2 0 012-2h10a2 2 0 012 2v16l-7-3.5L5 21V5z"></path>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
@@ -0,0 +1,82 @@
|
||||
@props(['product'])
|
||||
|
||||
<div class="card group">
|
||||
<a href="{{ route('products.show', $product) }}" class="block">
|
||||
<!-- Thumbnail -->
|
||||
<div class="aspect-video bg-gradient-to-br from-gray-100 to-gray-200 overflow-hidden">
|
||||
@if($product->thumbnail_url)
|
||||
<img src="{{ $product->thumbnail_url }}"
|
||||
alt="{{ $product->title }}"
|
||||
class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-200"
|
||||
loading="lazy">
|
||||
@else
|
||||
<div class="w-full h-full flex items-center justify-center">
|
||||
<svg class="h-16 w-16 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"></path>
|
||||
</svg>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</a>
|
||||
|
||||
<!-- Content -->
|
||||
<div class="p-4">
|
||||
<div class="flex items-start justify-between mb-2">
|
||||
<div class="flex-1 min-w-0">
|
||||
<a href="{{ route('products.show', $product) }}" class="group-hover:text-primary-600 transition-colors">
|
||||
<h3 class="text-lg font-semibold text-gray-900 truncate">{{ $product->title }}</h3>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Upvote Button Component -->
|
||||
@include('components.product.upvote-button', ['product' => $product])
|
||||
</div>
|
||||
|
||||
<!-- Description -->
|
||||
<p class="text-sm text-gray-600 line-clamp-2 mb-3">
|
||||
{{ Str::limit($product->description, 100) }}
|
||||
</p>
|
||||
|
||||
<!-- Meta Information -->
|
||||
<div class="flex items-center justify-between text-xs text-gray-500">
|
||||
<div class="flex items-center space-x-3">
|
||||
<!-- Category Badge -->
|
||||
<span class="badge bg-gray-100 text-gray-700">
|
||||
{{ $product->category->name }}
|
||||
</span>
|
||||
|
||||
<!-- Created At -->
|
||||
<span class="flex items-center">
|
||||
<svg class="h-3.5 w-3.5 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
{{ $product->created_at->diffForHumans() }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- User -->
|
||||
<a href="{{ route('profile.show', $product->user) }}" class="flex items-center space-x-1 hover:text-gray-900">
|
||||
<div class="h-5 w-5 rounded-full bg-gradient-to-br from-primary-500 to-accent-500 flex items-center justify-center text-white text-xs font-semibold">
|
||||
{{ strtoupper(substr($product->user->name, 0, 1)) }}
|
||||
</div>
|
||||
<span class="text-xs">{{ $product->user->name }}</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Action Buttons -->
|
||||
<div class="mt-3 pt-3 border-t border-gray-100 flex items-center justify-between">
|
||||
<a href="{{ route('products.show', $product) }}"
|
||||
class="text-sm font-medium text-primary-600 hover:text-primary-700 flex items-center">
|
||||
View details
|
||||
<svg class="h-4 w-4 ml-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path>
|
||||
</svg>
|
||||
</a>
|
||||
|
||||
<!-- Bookmark Button -->
|
||||
@auth
|
||||
@include('components.product.bookmark-button', ['product' => $product])
|
||||
@endauth
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,64 @@
|
||||
@props(['product', 'size' => 'sm'])
|
||||
|
||||
@php
|
||||
$isUpvoted = auth()->check() && $product->isUpvotedBy(auth()->user());
|
||||
$upvotesCount = isset($product->upvotes_count) ? $product->upvotes_count : $product->upvotes()->count();
|
||||
|
||||
$sizeClasses = match($size) {
|
||||
'lg' => 'h-12 w-12 text-base',
|
||||
'md' => 'h-10 w-10 text-sm',
|
||||
default => 'h-8 w-8 text-xs',
|
||||
};
|
||||
@endphp
|
||||
|
||||
<div x-data="{
|
||||
upvoted: {{ $isUpvoted ? 'true' : 'false' }},
|
||||
count: {{ $upvotesCount }},
|
||||
loading: false,
|
||||
toggleUpvote() {
|
||||
@guest
|
||||
window.location.href = '{{ route('login') }}';
|
||||
return;
|
||||
@endguest
|
||||
|
||||
if (this.loading) return;
|
||||
this.loading = true;
|
||||
|
||||
fetch('{{ route('products.upvote', $product) }}', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}',
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
this.upvoted = data.upvoted;
|
||||
this.count = data.upvotes_count;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
})
|
||||
.finally(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
}" class="flex-shrink-0">
|
||||
<button @click="toggleUpvote()"
|
||||
:disabled="loading"
|
||||
:class="{
|
||||
'bg-primary-100 border-primary-500 text-primary-700': upvoted,
|
||||
'bg-white border-gray-300 text-gray-700 hover:border-gray-400': !upvoted
|
||||
}"
|
||||
class="{{ $sizeClasses }} flex flex-col items-center justify-center border-2 rounded-lg transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed">
|
||||
<svg :class="{ 'animate-bounce': loading }"
|
||||
class="w-4 h-4"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 15l7-7 7 7"></path>
|
||||
</svg>
|
||||
<span class="font-semibold" x-text="count"></span>
|
||||
</button>
|
||||
</div>
|
||||
@@ -0,0 +1,67 @@
|
||||
@props([
|
||||
'name',
|
||||
'show' => false,
|
||||
'maxWidth' => 'md'
|
||||
])
|
||||
|
||||
@php
|
||||
$maxWidthClass = [
|
||||
'sm' => 'sm:max-w-sm',
|
||||
'md' => 'sm:max-w-md',
|
||||
'lg' => 'sm:max-w-lg',
|
||||
'xl' => 'sm:max-w-xl',
|
||||
'2xl' => 'sm:max-w-2xl',
|
||||
][$maxWidth];
|
||||
@endphp
|
||||
|
||||
<div x-data="{
|
||||
show: @js($show),
|
||||
focusables() {
|
||||
let selector = 'a, button, input:not([type=\'hidden\']), textarea, select, details, [tabindex]:not([tabindex=\'-1\'])'
|
||||
return [...this.$el.querySelectorAll(selector)]
|
||||
.filter(el => ! el.hasAttribute('disabled'))
|
||||
},
|
||||
firstFocusable() { return this.focusables()[0] },
|
||||
lastFocusable() { return this.focusables().slice(-1)[0] },
|
||||
nextFocusable() { return this.focusables()[this.nextFocusableIndex()] || this.firstFocusable() },
|
||||
prevFocusable() { return this.focusables()[this.prevFocusableIndex()] || this.lastFocusable() },
|
||||
nextFocusableIndex() { return (this.focusables().indexOf(document.activeElement) + 1) % (this.focusables().length + 1) },
|
||||
prevFocusableIndex() { return Math.max(0, this.focusables().indexOf(document.activeElement)) -1 },
|
||||
}"
|
||||
x-init="$watch('show', value => {
|
||||
if (value) {
|
||||
document.body.classList.add('overflow-hidden');
|
||||
{{ $attributes->has('focusable') ? 'setTimeout(() => firstFocusable().focus(), 100)' : '' }}
|
||||
} else {
|
||||
document.body.classList.remove('overflow-hidden');
|
||||
}
|
||||
})"
|
||||
x-on:open-modal.window="$event.detail == '{{ $name }}' ? show = true : null"
|
||||
x-on:close-modal.window="$event.detail == '{{ $name }}' ? show = false : null"
|
||||
x-on:close.stop="show = false"
|
||||
x-on:keydown.escape.window="show = false"
|
||||
x-on:keydown.tab.prevent="$event.shiftKey || nextFocusable().focus()"
|
||||
x-on:keydown.shift.tab.prevent="prevFocusable().focus()"
|
||||
x-show="show"
|
||||
class="fixed inset-0 overflow-y-auto px-4 py-6 sm:px-0 z-50"
|
||||
style="display: {{ $show ? 'block' : 'none' }};">
|
||||
<div x-show="show" class="fixed inset-0 transform transition-all" x-on:click="show = false"
|
||||
x-transition:enter="ease-out duration-300"
|
||||
x-transition:enter-start="opacity-0"
|
||||
x-transition:enter-end="opacity-100"
|
||||
x-transition:leave="ease-in duration-200"
|
||||
x-transition:leave-start="opacity-100"
|
||||
x-transition:leave-end="opacity-0">
|
||||
<div class="absolute inset-0 bg-gray-500 opacity-75"></div>
|
||||
</div>
|
||||
|
||||
<div x-show="show" class="mb-6 bg-white rounded-lg overflow-hidden shadow-xl transform transition-all sm:w-full sm:mx-auto {{ $maxWidthClass }}"
|
||||
x-transition:enter="ease-out duration-300"
|
||||
x-transition:enter-start="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
x-transition:enter-end="opacity-100 translate-y-0 sm:scale-100"
|
||||
x-transition:leave="ease-in duration-200"
|
||||
x-transition:leave-start="opacity-100 translate-y-0 sm:scale-100"
|
||||
x-transition:leave-end="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95">
|
||||
{{ $slot }}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,135 @@
|
||||
<!-- Toast Notifications -->
|
||||
<div x-data="{
|
||||
notices: [],
|
||||
visible: [],
|
||||
add(notice) {
|
||||
const id = Date.now();
|
||||
notice.id = id;
|
||||
this.notices.push(notice);
|
||||
this.visible.push(id);
|
||||
setTimeout(() => {
|
||||
this.remove(id);
|
||||
}, notice.duration || 5000);
|
||||
},
|
||||
remove(id) {
|
||||
const index = this.visible.indexOf(id);
|
||||
if (index > -1) {
|
||||
this.visible.splice(index, 1);
|
||||
}
|
||||
setTimeout(() => {
|
||||
const noticeIndex = this.notices.findIndex(n => n.id === id);
|
||||
if (noticeIndex > -1) {
|
||||
this.notices.splice(noticeIndex, 1);
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
}"
|
||||
@notify.window="add($event.detail)"
|
||||
class="fixed top-4 right-4 z-50 space-y-2"
|
||||
aria-live="assertive">
|
||||
<template x-for="notice in notices" :key="notice.id">
|
||||
<div x-show="visible.includes(notice.id)"
|
||||
x-transition:enter="transition ease-out duration-300"
|
||||
x-transition:enter-start="transform translate-x-full opacity-0"
|
||||
x-transition:enter-end="transform translate-x-0 opacity-100"
|
||||
x-transition:leave="transition ease-in duration-200"
|
||||
x-transition:leave-start="transform translate-x-0 opacity-100"
|
||||
x-transition:leave-end="transform translate-x-full opacity-0"
|
||||
class="max-w-sm w-full bg-white shadow-lg rounded-lg pointer-events-auto ring-1 ring-black ring-opacity-5 overflow-hidden">
|
||||
<div class="p-4">
|
||||
<div class="flex items-start">
|
||||
<div class="flex-shrink-0">
|
||||
<!-- Success Icon -->
|
||||
<template x-if="notice.type === 'success'">
|
||||
<svg class="h-6 w-6 text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
</template>
|
||||
<!-- Error Icon -->
|
||||
<template x-if="notice.type === 'error'">
|
||||
<svg class="h-6 w-6 text-red-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
</template>
|
||||
<!-- Info Icon -->
|
||||
<template x-if="notice.type === 'info'">
|
||||
<svg class="h-6 w-6 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
</template>
|
||||
<!-- Warning Icon -->
|
||||
<template x-if="notice.type === 'warning'">
|
||||
<svg class="h-6 w-6 text-yellow-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"></path>
|
||||
</svg>
|
||||
</template>
|
||||
</div>
|
||||
<div class="ml-3 w-0 flex-1 pt-0.5">
|
||||
<p class="text-sm font-medium text-gray-900" x-text="notice.title"></p>
|
||||
<p class="mt-1 text-sm text-gray-500" x-text="notice.message"></p>
|
||||
</div>
|
||||
<div class="ml-4 flex-shrink-0 flex">
|
||||
<button @click="remove(notice.id)"
|
||||
class="bg-white rounded-md inline-flex text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500">
|
||||
<span class="sr-only">Close</span>
|
||||
<svg class="h-5 w-5" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<!-- Session Messages (Laravel Flash Messages) -->
|
||||
@if(session('success') || session('error') || session('info') || session('warning'))
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
@if(session('success'))
|
||||
window.dispatchEvent(new CustomEvent('notify', {
|
||||
detail: {
|
||||
type: 'success',
|
||||
title: 'Success!',
|
||||
message: '{{ session('success') }}',
|
||||
duration: 5000
|
||||
}
|
||||
}));
|
||||
@endif
|
||||
|
||||
@if(session('error'))
|
||||
window.dispatchEvent(new CustomEvent('notify', {
|
||||
detail: {
|
||||
type: 'error',
|
||||
title: 'Error!',
|
||||
message: '{{ session('error') }}',
|
||||
duration: 5000
|
||||
}
|
||||
}));
|
||||
@endif
|
||||
|
||||
@if(session('info'))
|
||||
window.dispatchEvent(new CustomEvent('notify', {
|
||||
detail: {
|
||||
type: 'info',
|
||||
title: 'Info',
|
||||
message: '{{ session('info') }}',
|
||||
duration: 5000
|
||||
}
|
||||
}));
|
||||
@endif
|
||||
|
||||
@if(session('warning'))
|
||||
window.dispatchEvent(new CustomEvent('notify', {
|
||||
detail: {
|
||||
type: 'warning',
|
||||
title: 'Warning!',
|
||||
message: '{{ session('warning') }}',
|
||||
duration: 5000
|
||||
}
|
||||
}));
|
||||
@endif
|
||||
});
|
||||
</script>
|
||||
@endif
|
||||
Reference in New Issue
Block a user