feat: add lists page

This commit is contained in:
Levente Orban
2025-08-27 08:46:54 +02:00
parent c2874464d0
commit 9e4260c6bd
9 changed files with 361 additions and 9 deletions

View File

@@ -25,7 +25,7 @@
</button>
</div>
<!-- Desktop Navigation -->
<!-- Navigation -->
<div class="md:flex md:items-center md:space-x-8">
<button
on:click={() => navigateTo('/')}
@@ -40,6 +40,13 @@
>
Create
</button>
<button
on:click={() => navigateTo('/event')}
class={isActive('/event') ? 'text-violet-400' : 'cursor-pointer'}
>
List
</button>
</div>
</div>
</div>

View File

@@ -28,6 +28,7 @@ function convertDatabaseEvent(dbEvent: DatabaseEvent): Event {
location: dbEvent.location,
type: dbEvent.type,
attendee_limit: dbEvent.attendee_limit,
user_id: dbEvent.user_id,
created_at: dbEvent.created_at,
updated_at: dbEvent.updated_at
};
@@ -49,7 +50,7 @@ export const eventsStore = {
subscribeRSVPs: rsvps.subscribe,
// Create a new event
createEvent: async (eventData: CreateEventData): Promise<string> => {
createEvent: async (eventData: CreateEventData, userId: string): Promise<string> => {
const eventId = generateEventId();
const now = new Date().toISOString();
@@ -62,6 +63,7 @@ export const eventsStore = {
location: eventData.location,
type: eventData.type,
attendee_limit: eventData.attendee_limit,
user_id: userId,
created_at: now,
updated_at: now
});
@@ -72,6 +74,7 @@ export const eventsStore = {
const newEvent: Event = {
id: eventId,
...eventData,
user_id: userId,
created_at: now,
updated_at: now
};
@@ -245,5 +248,69 @@ export const eventsStore = {
console.error('Error fetching event with RSVPs:', error);
return undefined;
}
},
// Get events by user ID
getEventsByUser: async (userId: string): Promise<Event[]> => {
try {
const { data, error } = await supabase
.from('events')
.select('*')
.eq('user_id', userId)
.order('created_at', { ascending: false });
if (error) throw error;
const userEvents = data?.map(convertDatabaseEvent) || [];
// Update local store
userEvents.forEach((event) => {
events.update((currentEvents) => {
const newMap = new Map(currentEvents);
newMap.set(event.id, event);
return newMap;
});
});
return userEvents;
} catch (error) {
console.error('Error fetching user events:', error);
return [];
}
},
// Delete event (only by the user who created it)
deleteEvent: async (eventId: string, userId: string): Promise<boolean> => {
try {
// First verify the user owns this event
const event = await eventsStore.getEvent(eventId);
if (!event || event.user_id !== userId) {
return false; // User doesn't own this event
}
// Delete the event (RSVPs will be deleted automatically due to CASCADE)
const { error } = await supabase.from('events').delete().eq('id', eventId);
if (error) throw error;
// Remove from local store
events.update((currentEvents) => {
const newMap = new Map(currentEvents);
newMap.delete(eventId);
return newMap;
});
// Remove RSVPs from local store
rsvps.update((currentRSVPs) => {
const newMap = new Map(currentRSVPs);
newMap.delete(eventId);
return newMap;
});
return true;
} catch (error) {
console.error('Error deleting event:', error);
return false;
}
}
};

View File

@@ -8,6 +8,7 @@ export interface Event {
location: string;
type: EventType;
attendee_limit?: number;
user_id: string;
created_at: string;
updated_at: string;
}
@@ -37,6 +38,7 @@ export interface DatabaseEvent {
location: string;
type: EventType;
attendee_limit?: number;
user_id: string;
created_at: string;
updated_at: string;
}