feat: add public/private event types

This commit is contained in:
Levente Orban
2025-08-27 08:47:05 +02:00
parent a91f863295
commit 4c387a10f1
9 changed files with 313 additions and 12 deletions

View File

@@ -14,7 +14,7 @@
<nav class="relative z-50 backdrop-blur-md">
<div class="container mx-auto px-4">
<div class="flex h-16 items-center justify-between">
<div class="mt-4 flex h-16 flex-col items-center justify-between">
<!-- Logo/Brand -->
<div class="flex items-center">
<button
@@ -34,6 +34,13 @@
Home
</button>
<button
on:click={() => navigateTo('/discover')}
class={isActive('/discover') ? 'text-violet-400' : 'cursor-pointer'}
>
Discover
</button>
<button
on:click={() => navigateTo('/create')}
class={isActive('/create') ? 'text-violet-400' : 'cursor-pointer'}
@@ -45,7 +52,7 @@
on:click={() => navigateTo('/event')}
class={isActive('/event') ? 'text-violet-400' : 'cursor-pointer'}
>
List
My Events
</button>
</div>
</div>

View File

@@ -28,6 +28,7 @@ function convertDatabaseEvent(dbEvent: DatabaseEvent): Event {
location: dbEvent.location,
type: dbEvent.type,
attendee_limit: dbEvent.attendee_limit,
visibility: dbEvent.visibility,
user_id: dbEvent.user_id,
created_at: dbEvent.created_at,
updated_at: dbEvent.updated_at
@@ -63,6 +64,7 @@ export const eventsStore = {
location: eventData.location,
type: eventData.type,
attendee_limit: eventData.attendee_limit,
visibility: eventData.visibility,
user_id: userId,
created_at: now,
updated_at: now
@@ -279,6 +281,35 @@ export const eventsStore = {
}
},
// Get public events
getPublicEvents: async (): Promise<Event[]> => {
try {
const { data, error } = await supabase
.from('events')
.select('*')
.eq('visibility', 'public')
.order('created_at', { ascending: false });
if (error) throw error;
const publicEvents = data?.map(convertDatabaseEvent) || [];
// Update local store
publicEvents.forEach((event) => {
events.update((currentEvents) => {
const newMap = new Map(currentEvents);
newMap.set(event.id, event);
return newMap;
});
});
return publicEvents;
} catch (error) {
console.error('Error fetching public events:', error);
return [];
}
},
// Delete event (only by the user who created it)
deleteEvent: async (eventId: string, userId: string): Promise<boolean> => {
try {

View File

@@ -1,4 +1,5 @@
export type EventType = 'limited' | 'unlimited';
export type EventVisibility = 'public' | 'private';
export interface Event {
id: string;
@@ -8,6 +9,7 @@ export interface Event {
location: string;
type: EventType;
attendee_limit?: number;
visibility: EventVisibility;
user_id: string;
created_at: string;
updated_at: string;
@@ -28,6 +30,7 @@ export interface CreateEventData {
location: string;
type: EventType;
attendee_limit?: number;
visibility: EventVisibility;
}
export interface DatabaseEvent {
@@ -38,6 +41,7 @@ export interface DatabaseEvent {
location: string;
type: EventType;
attendee_limit?: number;
visibility: EventVisibility;
user_id: string;
created_at: string;
updated_at: string;