From c325f90e77d9fe81df488ebf25b8131fe19d0922 Mon Sep 17 00:00:00 2001 From: peperoli Date: Wed, 31 Jul 2024 09:59:59 +0200 Subject: [PATCH] Feat: Add meta info to concerts, bands and locations --- app/bands/[id]/page.tsx | 7 ++- app/concerts/[id]/page.tsx | 3 +- app/locations/[id]/page.tsx | 2 +- components/bands/BandPage.tsx | 4 ++ components/concerts/ConcertPage.tsx | 2 + components/locations/LocationPage.tsx | 4 ++ components/shared/MetaInfo.tsx | 28 ++++++++++++ hooks/bands/useBand.ts | 8 +++- hooks/concerts/useConcert.ts | 3 +- hooks/locations/useLocation.ts | 2 +- types/supabase.ts | 62 +++++++++++++++++++++++++-- types/types.ts | 3 ++ 12 files changed, 119 insertions(+), 9 deletions(-) create mode 100644 components/shared/MetaInfo.tsx diff --git a/app/bands/[id]/page.tsx b/app/bands/[id]/page.tsx index 44aea66..0f2cbb2 100644 --- a/app/bands/[id]/page.tsx +++ b/app/bands/[id]/page.tsx @@ -18,7 +18,12 @@ async function fetchData(params: { id: string }) { const { data, error } = await supabase .from('bands') - .select('*, country:countries(id, iso2, name), genres(*)') + .select( + `*, + country:countries(id, iso2, name), + genres(*), + creator:profiles!bands_creator_id_fkey(*)` + ) .eq('id', params.id) .single() diff --git a/app/concerts/[id]/page.tsx b/app/concerts/[id]/page.tsx index da4841e..839a5e4 100644 --- a/app/concerts/[id]/page.tsx +++ b/app/concerts/[id]/page.tsx @@ -23,7 +23,8 @@ async function fetchConcert(concertId: string) { `*, location:locations(*), bands:j_concert_bands(*, ...bands(*, country:countries(id, iso2), genres(*))), - bands_seen:j_bands_seen(*)` + bands_seen:j_bands_seen(*), + creator:profiles!concerts_creator_id_fkey(*)` ) .eq('id', concertId) .order('item_index', { referencedTable: 'j_concert_bands', ascending: true }) diff --git a/app/locations/[id]/page.tsx b/app/locations/[id]/page.tsx index 4a426d0..ae16d6a 100644 --- a/app/locations/[id]/page.tsx +++ b/app/locations/[id]/page.tsx @@ -19,7 +19,7 @@ async function fetchData(params: { id: string }) { const { data, error } = await supabase .from('locations') - .select('*, country:countries(id, iso2)') + .select('*, country:countries(id, iso2), creator:profiles!locations_creator_id_fkey(*)') .eq('id', params.id) .single() diff --git a/components/bands/BandPage.tsx b/components/bands/BandPage.tsx index 00922e7..347774d 100644 --- a/components/bands/BandPage.tsx +++ b/components/bands/BandPage.tsx @@ -17,6 +17,7 @@ import { useSpotifyArtist } from '@/hooks/spotify/useSpotifyArtist' import { UserItem } from '../shared/UserItem' import { useBandProfiles } from '@/hooks/bands/useBandProfiles' import { UserMusicIcon } from '../layout/UserMusicIcon' +import { MetaInfo } from '../shared/MetaInfo' type BandPageProps = { initialBand: Band @@ -156,6 +157,9 @@ export const BandPage = ({ initialBand, bandQueryState }: BandPageProps) => { {concerts?.data.map(item => )} )} + {(band.created_at || band.creator_id) && ( + + )} ) } diff --git a/components/concerts/ConcertPage.tsx b/components/concerts/ConcertPage.tsx index dab3438..d3df1d2 100644 --- a/components/concerts/ConcertPage.tsx +++ b/components/concerts/ConcertPage.tsx @@ -22,6 +22,7 @@ import { parseAsStringLiteral, useQueryState } from 'nuqs' import { modalPaths } from '../shared/ModalProvider' import { useConcertProfiles } from '@/hooks/concerts/useConcertProfiles' import { Chip } from '../Chip' +import { MetaInfo } from '../shared/MetaInfo' type ConcertUserItemProps = { concert: Concert @@ -176,6 +177,7 @@ export const ConcertPage = ({ initialConcert, concertQueryState }: ConcertPagePr
+ ) diff --git a/components/locations/LocationPage.tsx b/components/locations/LocationPage.tsx index e6a3257..b89bb1d 100644 --- a/components/locations/LocationPage.tsx +++ b/components/locations/LocationPage.tsx @@ -13,6 +13,7 @@ import { ArrowLeft, Edit, MapPin, Trash } from 'lucide-react' import { UserItem } from '../shared/UserItem' import { useLocation } from '@/hooks/locations/useLocation' import { useLocationProfiles } from '@/hooks/locations/useLocationProfiles' +import { MetaInfo } from '../shared/MetaInfo' type LocationPageProps = { location: Location @@ -140,6 +141,9 @@ export const LocationPage = ({ {concerts?.data.map(item => )} )} + {(location.created_at || location.creator_id) && ( + + )} ) } diff --git a/components/shared/MetaInfo.tsx b/components/shared/MetaInfo.tsx new file mode 100644 index 0000000..0047bb3 --- /dev/null +++ b/components/shared/MetaInfo.tsx @@ -0,0 +1,28 @@ +import { InfoIcon } from 'lucide-react' +import Link from 'next/link' + +type MetaInfoProps = { + createdAt: string | null + creator?: { + username: string + } | null +} + +export const MetaInfo = ({ createdAt, creator }: MetaInfoProps) => { + return ( +
+ +

+ Erstellt {createdAt && `am ${new Date(createdAt).toLocaleDateString('de-CH')}`} + {creator && ( + <> + {' von '} + + {creator.username} + + + )} +

+
+ ) +} diff --git a/hooks/bands/useBand.ts b/hooks/bands/useBand.ts index 1e542d6..ddfb2b1 100644 --- a/hooks/bands/useBand.ts +++ b/hooks/bands/useBand.ts @@ -5,7 +5,13 @@ import supabase from '@/utils/supabase/client' const fetchBand = async (bandId: number): Promise => { const { data, error } = await supabase .from('bands') - .select('*, country:countries(id, iso2), genres(*), concerts!j_concert_bands(*)') + .select( + `*, + country:countries(id, iso2), + genres(*), + concerts!j_concert_bands(*), + creator:profiles!bands_creator_id_fkey(*)` + ) .eq('id', bandId) .single() diff --git a/hooks/concerts/useConcert.ts b/hooks/concerts/useConcert.ts index c2ee93f..4af09ce 100644 --- a/hooks/concerts/useConcert.ts +++ b/hooks/concerts/useConcert.ts @@ -14,7 +14,8 @@ const fetchConcert = async (concertId: string | null): Promise => { festival_root:festival_roots(name), location:locations(*), bands:j_concert_bands(*, ...bands(*, country:countries(id, iso2), genres(*))), - bands_seen:j_bands_seen(*)` + bands_seen:j_bands_seen(*), + creator:profiles!concerts_creator_id_fkey(username)` ) .eq('id', concertId) .order('item_index', { referencedTable: 'j_concert_bands', ascending: true }) diff --git a/hooks/locations/useLocation.ts b/hooks/locations/useLocation.ts index 8191158..00e78c0 100644 --- a/hooks/locations/useLocation.ts +++ b/hooks/locations/useLocation.ts @@ -5,7 +5,7 @@ import { Location } from '@/types/types' async function fetchLocation(id: number): Promise { const { data, error } = await supabase .from('locations') - .select('*, country:countries(id, iso2)') + .select('*, country:countries(id, iso2), creator:profiles!locations_creator_id_fkey(*)') .eq('id', id) .single() diff --git a/types/supabase.ts b/types/supabase.ts index bafe84e..6f7edf5 100644 --- a/types/supabase.ts +++ b/types/supabase.ts @@ -45,6 +45,20 @@ export type Database = { referencedRelation: "countries" referencedColumns: ["id"] }, + { + foreignKeyName: "bands_creator_id_fkey" + columns: ["creator_id"] + isOneToOne: false + referencedRelation: "profile_stats" + referencedColumns: ["id"] + }, + { + foreignKeyName: "bands_creator_id_fkey" + columns: ["creator_id"] + isOneToOne: false + referencedRelation: "profiles" + referencedColumns: ["id"] + }, { foreignKeyName: "public_bands_creator_id_fkey" columns: ["creator_id"] @@ -98,7 +112,7 @@ export type Database = { } concerts: { Row: { - created_at: string | null + created_at: string creator_id: string | null date_end: string | null date_start: string @@ -109,7 +123,7 @@ export type Database = { name: string | null } Insert: { - created_at?: string | null + created_at?: string creator_id?: string | null date_end?: string | null date_start: string @@ -120,7 +134,7 @@ export type Database = { name?: string | null } Update: { - created_at?: string | null + created_at?: string creator_id?: string | null date_end?: string | null date_start?: string @@ -131,6 +145,20 @@ export type Database = { name?: string | null } Relationships: [ + { + foreignKeyName: "concerts_creator_id_fkey" + columns: ["creator_id"] + isOneToOne: false + referencedRelation: "profile_stats" + referencedColumns: ["id"] + }, + { + foreignKeyName: "concerts_creator_id_fkey" + columns: ["creator_id"] + isOneToOne: false + referencedRelation: "profiles" + referencedColumns: ["id"] + }, { foreignKeyName: "concerts_location_id_fkey" columns: ["location_id"] @@ -481,6 +509,20 @@ export type Database = { zip_code?: string | null } Relationships: [ + { + foreignKeyName: "locations_creator_id_fkey" + columns: ["creator_id"] + isOneToOne: false + referencedRelation: "profile_stats" + referencedColumns: ["id"] + }, + { + foreignKeyName: "locations_creator_id_fkey" + columns: ["creator_id"] + isOneToOne: false + referencedRelation: "profiles" + referencedColumns: ["id"] + }, { foreignKeyName: "public_locations_country_id_fkey" columns: ["country_id"] @@ -596,6 +638,20 @@ export type Database = { name: string | null } Relationships: [ + { + foreignKeyName: "concerts_creator_id_fkey" + columns: ["creator_id"] + isOneToOne: false + referencedRelation: "profiles" + referencedColumns: ["id"] + }, + { + foreignKeyName: "concerts_creator_id_fkey" + columns: ["creator_id"] + isOneToOne: false + referencedRelation: "profile_stats" + referencedColumns: ["id"] + }, { foreignKeyName: "concerts_location_id_fkey" columns: ["location_id"] diff --git a/types/types.ts b/types/types.ts index 143fc43..887d895 100644 --- a/types/types.ts +++ b/types/types.ts @@ -41,6 +41,7 @@ export type Concert = Tables<'concerts'> & { location?: Location | null bands?: Band[] bands_seen?: BandSeen[] + creator?: { username: string } | null } export type AddConcert = TablesInsert<'concerts'> & { @@ -70,6 +71,7 @@ export type Band = Tables<'bands'> & { genres: Genre[] concerts?: Concert[] item_index?: number | null + creator?: { username: string } | null } export type AddBand = TablesInsert<'bands'> & { @@ -89,6 +91,7 @@ export type Genre = Tables<'genres'> export type Location = Tables<'locations'> & { country?: Country | null + creator?: { username: string } | null } export type AddLocation = TablesInsert<'locations'>