mirror of
https://github.com/0xShay/ticketchain.git
synced 2026-01-11 21:23:24 +00:00
@@ -1,5 +1,5 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState, useRef } from 'react';
|
||||||
import Header from '../../components/custom/header';
|
import Header from '../../components/custom/header';
|
||||||
import Footer from '../../components/custom/footer';
|
import Footer from '../../components/custom/footer';
|
||||||
|
|
||||||
@@ -7,13 +7,14 @@ import Footer from '../../components/custom/footer';
|
|||||||
interface Event {
|
interface Event {
|
||||||
EventID: number;
|
EventID: number;
|
||||||
name: string;
|
name: string;
|
||||||
date: string;
|
date: string; // Should ideally be a Date object for better handling
|
||||||
location: string;
|
location: string;
|
||||||
ticketPrice: string;
|
ticketPrice: number; // Changed to number for sorting
|
||||||
description: string;
|
description: string;
|
||||||
capacity: number;
|
capacity: number;
|
||||||
ticketsSold: number;
|
ticketsSold: number;
|
||||||
imageUrl: string;
|
imageUrl: string;
|
||||||
|
host: string; // New field for host
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dummy function to fetch events
|
// Dummy function to fetch events
|
||||||
@@ -24,50 +25,129 @@ const fetchEvents = (): Event[] => {
|
|||||||
name: 'Rock Concert',
|
name: 'Rock Concert',
|
||||||
date: '2023-12-01',
|
date: '2023-12-01',
|
||||||
location: 'New York City',
|
location: 'New York City',
|
||||||
ticketPrice: '$99',
|
ticketPrice: 99,
|
||||||
description: 'An exhilarating rock concert featuring famous bands.',
|
description: 'An exhilarating rock concert featuring famous bands.',
|
||||||
capacity: 5000,
|
capacity: 5000,
|
||||||
ticketsSold: 4500,
|
ticketsSold: 4500,
|
||||||
imageUrl: 'https://via.placeholder.com/150',
|
imageUrl: 'https://via.placeholder.com/150',
|
||||||
|
host: 'Music Mania',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
EventID: 2,
|
EventID: 2,
|
||||||
name: 'Art Expo',
|
name: 'Art Expo',
|
||||||
date: '2023-11-15',
|
date: '2023-11-15',
|
||||||
location: 'San Francisco',
|
location: 'San Francisco',
|
||||||
ticketPrice: '$55',
|
ticketPrice: 55,
|
||||||
description: 'A showcase of modern art from around the world.',
|
description: 'A showcase of modern art from around the world.',
|
||||||
capacity: 300,
|
capacity: 300,
|
||||||
ticketsSold: 260,
|
ticketsSold: 260,
|
||||||
imageUrl: 'https://via.placeholder.com/150',
|
imageUrl: 'https://via.placeholder.com/150',
|
||||||
|
host: 'Art Lovers',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
EventID: 3,
|
EventID: 3,
|
||||||
name: 'Tech Summit 2023',
|
name: 'Tech Summit 2023',
|
||||||
date: '2023-12-10',
|
date: '2023-12-10',
|
||||||
location: 'Chicago',
|
location: 'Chicago',
|
||||||
ticketPrice: '$250',
|
ticketPrice: 250,
|
||||||
description: 'The leading tech summit with top industry speakers.',
|
description: 'The leading tech summit with top industry speakers.',
|
||||||
capacity: 2000,
|
capacity: 2000,
|
||||||
ticketsSold: 1800,
|
ticketsSold: 1800,
|
||||||
imageUrl: 'https://via.placeholder.com/150',
|
imageUrl: 'https://via.placeholder.com/150',
|
||||||
|
host: 'Tech Alliance',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
const TicketListing: React.FC = () => {
|
const TicketListing: React.FC = () => {
|
||||||
const [events, setEvents] = useState<Event[]>([]);
|
const [events, setEvents] = useState<Event[]>([]);
|
||||||
|
const [filteredEvents, setFilteredEvents] = useState<Event[]>([]);
|
||||||
|
const [searchQuery, setSearchQuery] = useState<string>('');
|
||||||
const [hoveredEventId, setHoveredEventId] = useState<number | null>(null);
|
const [hoveredEventId, setHoveredEventId] = useState<number | null>(null);
|
||||||
|
const [sortOption, setSortOption] = useState<string>(''); // Track sorting option
|
||||||
|
const [filterOptions, setFilterOptions] = useState<string[]>([]); // Track applied filters
|
||||||
|
const [selectedHost, setSelectedHost] = useState<string>(''); // For host filtering
|
||||||
|
const [showSortMenu, setShowSortMenu] = useState<boolean>(false);
|
||||||
|
const [showFilterMenu, setShowFilterMenu] = useState<boolean>(false);
|
||||||
|
|
||||||
|
const sortRef = useRef<HTMLDivElement>(null);
|
||||||
|
const filterRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const eventsData = fetchEvents();
|
const eventsData = fetchEvents();
|
||||||
setEvents(eventsData);
|
setEvents(eventsData);
|
||||||
|
setFilteredEvents(eventsData);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let filtered = events.filter((event) =>
|
||||||
|
['name', 'date', 'location', 'description', 'host'].some((key) =>
|
||||||
|
event[key as keyof Event]
|
||||||
|
.toString()
|
||||||
|
.toLowerCase()
|
||||||
|
.includes(searchQuery.toLowerCase())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (filterOptions.includes('limited')) {
|
||||||
|
filtered = filtered.filter(
|
||||||
|
(event) => event.ticketsSold / event.capacity >= 0.9
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filterOptions.includes('future')) {
|
||||||
|
const now = new Date();
|
||||||
|
filtered = filtered.filter((event) => new Date(event.date) > now);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filterOptions.includes('past')) {
|
||||||
|
const now = new Date();
|
||||||
|
filtered = filtered.filter((event) => new Date(event.date) < now);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedHost) {
|
||||||
|
filtered = filtered.filter((event) => event.host === selectedHost);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sortOption === 'price-asc') {
|
||||||
|
filtered = filtered.sort((a, b) => a.ticketPrice - b.ticketPrice);
|
||||||
|
} else if (sortOption === 'price-desc') {
|
||||||
|
filtered = filtered.sort((a, b) => b.ticketPrice - a.ticketPrice);
|
||||||
|
} else if (sortOption === 'date-asc') {
|
||||||
|
filtered = filtered.sort(
|
||||||
|
(a, b) => new Date(a.date).getTime() - new Date(b.date).getTime()
|
||||||
|
);
|
||||||
|
} else if (sortOption === 'date-desc') {
|
||||||
|
filtered = filtered.sort(
|
||||||
|
(a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
setFilteredEvents(filtered);
|
||||||
|
}, [searchQuery, sortOption, filterOptions, selectedHost, events]);
|
||||||
|
|
||||||
|
const handleClickOutside = (event: MouseEvent) => {
|
||||||
|
if (sortRef.current && !sortRef.current.contains(event.target as Node)) {
|
||||||
|
setShowSortMenu(false);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
filterRef.current &&
|
||||||
|
!filterRef.current.contains(event.target as Node)
|
||||||
|
) {
|
||||||
|
setShowFilterMenu(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
document.addEventListener('mousedown', handleClickOutside);
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('mousedown', handleClickOutside);
|
||||||
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative min-h-screen overflow-hidden">
|
<div className="relative min-h-screen overflow-hidden">
|
||||||
<Header />
|
<Header />
|
||||||
{/* Video Background */}
|
|
||||||
<video
|
<video
|
||||||
autoPlay
|
autoPlay
|
||||||
loop
|
loop
|
||||||
@@ -77,33 +157,146 @@ const TicketListing: React.FC = () => {
|
|||||||
>
|
>
|
||||||
Your browser does not support the video tag.
|
Your browser does not support the video tag.
|
||||||
</video>
|
</video>
|
||||||
{/* Overlay for Readability */}
|
|
||||||
<div className="absolute inset-0 bg-black opacity-50 z-10"></div>
|
<div className="absolute inset-0 bg-black opacity-50 z-10"></div>
|
||||||
|
|
||||||
{/* Main Content */}
|
|
||||||
<div className="relative z-20 container mx-auto p-4 pt-16">
|
<div className="relative z-20 container mx-auto p-4 pt-16">
|
||||||
<div className="mb-6">
|
<div className="mb-6">
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Search events..."
|
placeholder="Search events..."
|
||||||
|
value={searchQuery}
|
||||||
|
onChange={(e) => setSearchQuery(e.target.value)}
|
||||||
className="search-bar mt-4 p-2 border border-gray-300 rounded w-full max-w-md"
|
className="search-bar mt-4 p-2 border border-gray-300 rounded w-full max-w-md"
|
||||||
/>
|
/>
|
||||||
<div className="flex mt-4 space-x-4">
|
<div className="flex mt-4 space-x-4">
|
||||||
<button className="bg-blue-500 text-white px-4 py-2 rounded">
|
{/* Sort Button and Dropdown */}
|
||||||
|
<div className="relative" ref={sortRef}>
|
||||||
|
<button
|
||||||
|
className="bg-blue-500 text-white px-4 py-2 rounded"
|
||||||
|
onClick={() => setShowSortMenu(!showSortMenu)}
|
||||||
|
>
|
||||||
Sort
|
Sort
|
||||||
</button>
|
</button>
|
||||||
<button className="bg-blue-500 text-white px-4 py-2 rounded">
|
{showSortMenu && (
|
||||||
Filter
|
<div className="absolute left-0 mt-2 p-2 bg-white shadow-lg rounded border border-gray-300 z-30">
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
setSortOption('price-asc');
|
||||||
|
setShowSortMenu(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Price Ascending
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
setSortOption('price-desc');
|
||||||
|
setShowSortMenu(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Price Descending
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
setSortOption('date-asc');
|
||||||
|
setShowSortMenu(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Date Ascending
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
setSortOption('date-desc');
|
||||||
|
setShowSortMenu(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Date Descending
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Filter Button and Dropdown */}
|
||||||
|
<div className="relative" ref={filterRef}>
|
||||||
|
<button
|
||||||
|
className="bg-blue-500 text-white px-4 py-2 rounded"
|
||||||
|
onClick={() => setShowFilterMenu(!showFilterMenu)}
|
||||||
|
>
|
||||||
|
Filters
|
||||||
|
</button>
|
||||||
|
{showFilterMenu && (
|
||||||
|
<div className="absolute left-0 mt-2 p-2 bg-white shadow-lg rounded border border-gray-300 z-30">
|
||||||
|
<label className="flex items-center">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={filterOptions.includes('limited')}
|
||||||
|
onChange={(e) => {
|
||||||
|
const newFilters = e.target.checked
|
||||||
|
? [...filterOptions, 'limited']
|
||||||
|
: filterOptions.filter(
|
||||||
|
(filter) => filter !== 'limited'
|
||||||
|
);
|
||||||
|
setFilterOptions(newFilters);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<span className="ml-2">Limited Tickets</span>
|
||||||
|
</label>
|
||||||
|
<label className="flex items-center">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={filterOptions.includes('future')}
|
||||||
|
onChange={(e) => {
|
||||||
|
const newFilters = e.target.checked
|
||||||
|
? [...filterOptions, 'future']
|
||||||
|
: filterOptions.filter(
|
||||||
|
(filter) => filter !== 'future'
|
||||||
|
);
|
||||||
|
setFilterOptions(newFilters);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<span className="ml-2">Future Events</span>
|
||||||
|
</label>
|
||||||
|
<label className="flex items-center">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={filterOptions.includes('past')}
|
||||||
|
onChange={(e) => {
|
||||||
|
const newFilters = e.target.checked
|
||||||
|
? [...filterOptions, 'past']
|
||||||
|
: filterOptions.filter((filter) => filter !== 'past');
|
||||||
|
setFilterOptions(newFilters);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<span className="ml-2">Past Events</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
{/* Filter by Host */}
|
||||||
|
<select
|
||||||
|
value={selectedHost}
|
||||||
|
onChange={(e) => setSelectedHost(e.target.value)}
|
||||||
|
className="mt-1 block w-full border-gray-300 rounded"
|
||||||
|
>
|
||||||
|
<option value="">All Hosts</option>
|
||||||
|
{Array.from(new Set(events.map((event) => event.host))).map(
|
||||||
|
(host) => (
|
||||||
|
<option key={host} value={host}>
|
||||||
|
{host}
|
||||||
|
</option>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<section>
|
<section>
|
||||||
<h2 className="text-2xl font-semibold text-white mb-4">
|
<h2 className="text-2xl font-semibold text-white mb-4">
|
||||||
Available Events
|
Available Events
|
||||||
</h2>
|
</h2>
|
||||||
<div className="grid grid-cols-1 gap-6">
|
<div className="grid grid-cols-1 gap-6">
|
||||||
{events.map((event) => (
|
{filteredEvents.map((event) => (
|
||||||
<div
|
<div
|
||||||
key={event.EventID}
|
key={event.EventID}
|
||||||
className="relative flex bg-white p-4 rounded-lg shadow-lg"
|
className="relative flex bg-white p-4 rounded-lg shadow-lg"
|
||||||
@@ -120,8 +313,9 @@ const TicketListing: React.FC = () => {
|
|||||||
<p className="text-gray-600">{event.date}</p>
|
<p className="text-gray-600">{event.date}</p>
|
||||||
<p className="text-gray-600">{event.location}</p>
|
<p className="text-gray-600">{event.location}</p>
|
||||||
<p className="text-gray-800 font-semibold">
|
<p className="text-gray-800 font-semibold">
|
||||||
{event.ticketPrice}
|
${event.ticketPrice.toFixed(2)}
|
||||||
</p>
|
</p>
|
||||||
|
<p className="text-gray-600">Host: {event.host}</p>
|
||||||
{event.ticketsSold / event.capacity >= 0.9 && (
|
{event.ticketsSold / event.capacity >= 0.9 && (
|
||||||
<div className="mt-2 p-2 bg-yellow-300 text-black rounded">
|
<div className="mt-2 p-2 bg-yellow-300 text-black rounded">
|
||||||
Limited Tickets Remaining!
|
Limited Tickets Remaining!
|
||||||
|
|||||||
105
package-lock.json
generated
105
package-lock.json
generated
@@ -24012,6 +24012,111 @@
|
|||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@next/swc-darwin-arm64": {
|
||||||
|
"version": "14.2.13",
|
||||||
|
"resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.13.tgz",
|
||||||
|
"integrity": "sha512-IkAmQEa2Htq+wHACBxOsslt+jMoV3msvxCn0WFSfJSkv/scy+i/EukBKNad36grRxywaXUYJc9mxEGkeIs8Bzg==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"darwin"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@next/swc-darwin-x64": {
|
||||||
|
"version": "14.2.13",
|
||||||
|
"resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.13.tgz",
|
||||||
|
"integrity": "sha512-Dv1RBGs2TTjkwEnFMVL5XIfJEavnLqqwYSD6LXgTPdEy/u6FlSrLBSSfe1pcfqhFEXRAgVL3Wpjibe5wXJzWog==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"darwin"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@next/swc-linux-arm64-gnu": {
|
||||||
|
"version": "14.2.13",
|
||||||
|
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.13.tgz",
|
||||||
|
"integrity": "sha512-yB1tYEFFqo4ZNWkwrJultbsw7NPAAxlPXURXioRl9SdW6aIefOLS+0TEsKrWBtbJ9moTDgU3HRILL6QBQnMevg==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@next/swc-linux-arm64-musl": {
|
||||||
|
"version": "14.2.13",
|
||||||
|
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.13.tgz",
|
||||||
|
"integrity": "sha512-v5jZ/FV/eHGoWhMKYrsAweQ7CWb8xsWGM/8m1mwwZQ/sutJjoFaXchwK4pX8NqwImILEvQmZWyb8pPTcP7htWg==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@next/swc-win32-arm64-msvc": {
|
||||||
|
"version": "14.2.13",
|
||||||
|
"resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.13.tgz",
|
||||||
|
"integrity": "sha512-uP1XkqCqV2NVH9+g2sC7qIw+w2tRbcMiXFEbMihkQ8B1+V6m28sshBwAB0SDmOe0u44ne1vFU66+gx/28RsBVQ==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"win32"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@next/swc-win32-ia32-msvc": {
|
||||||
|
"version": "14.2.13",
|
||||||
|
"resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.13.tgz",
|
||||||
|
"integrity": "sha512-V26ezyjPqQpDBV4lcWIh8B/QICQ4v+M5Bo9ykLN+sqeKKBxJVDpEc6biDVyluTXTC40f5IqCU0ttth7Es2ZuMw==",
|
||||||
|
"cpu": [
|
||||||
|
"ia32"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"win32"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@next/swc-win32-x64-msvc": {
|
||||||
|
"version": "14.2.13",
|
||||||
|
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.13.tgz",
|
||||||
|
"integrity": "sha512-WwzOEAFBGhlDHE5Z73mNU8CO8mqMNLqaG+AO9ETmzdCQlJhVtWZnOl2+rqgVQS+YHunjOWptdFmNfbpwcUuEsw==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"win32"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 10"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user