From 129a01600b1cfeaed1fb45da73cf71b46e2d85f2 Mon Sep 17 00:00:00 2001 From: Terry Sutton Date: Thu, 29 Feb 2024 17:45:56 -0330 Subject: [PATCH] Add redirect --- apps/database-new/app/t/[slug]/page.tsx | 5 ++--- .../components/Header/SaveSchemaDropdown.tsx | 3 +-- .../migrations/20231122191507_get_started.sql | 18 ++++++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/apps/database-new/app/t/[slug]/page.tsx b/apps/database-new/app/t/[slug]/page.tsx index 9efd4359ced..7550c11a385 100644 --- a/apps/database-new/app/t/[slug]/page.tsx +++ b/apps/database-new/app/t/[slug]/page.tsx @@ -12,12 +12,11 @@ export default async function Page({ params }: PageProps) { // maybe a mis-use of profile_threads here // it has both the thread_id and the latest message_id + // need to handle error fallback here const { data, error } = await supabase .from('profile_threads') .select() - .eq('thread_id', '942ac327-f9bf-44a7-9310-0d0f5b04cbe4') - - //.ilike('thread_id', `%${params.slug}%`) + .ilike('slug', `%${params.slug}%`) .single() // immediately redirect to the thread diff --git a/apps/database-new/components/Header/SaveSchemaDropdown.tsx b/apps/database-new/components/Header/SaveSchemaDropdown.tsx index cb3c924b9cd..07fcaada104 100644 --- a/apps/database-new/components/Header/SaveSchemaDropdown.tsx +++ b/apps/database-new/components/Header/SaveSchemaDropdown.tsx @@ -33,8 +33,7 @@ const SaveSchemaDropdown = () => { const shareSchema = () => { console.log({ params }) - const shareUrl = SITE_URL + '/' + thread_id.substring(0, 8) - const snap = getAppStateSnapshot() + const shareUrl = SITE_URL + '/t/' + thread_id.substring(0, 8) const focused = window.document.hasFocus() if (focused) { window.navigator?.clipboard?.writeText(shareUrl) diff --git a/apps/database-new/supabase/migrations/20231122191507_get_started.sql b/apps/database-new/supabase/migrations/20231122191507_get_started.sql index 77ac5125eb2..df0b50615ad 100644 --- a/apps/database-new/supabase/migrations/20231122191507_get_started.sql +++ b/apps/database-new/supabase/migrations/20231122191507_get_started.sql @@ -4,6 +4,7 @@ create table if not exists public.threads ( user_id uuid null, thread_title text not null, is_public boolean default true not null, + slug text generated always as (substring(id::text, 1, 8)) stored unique, constraint threads_pkey primary key (id), constraint threads_user_id_fkey foreign key (user_id) references auth.users (id) on update cascade on delete cascade ); @@ -21,20 +22,21 @@ create table if not exists public.messages ( constraint messages_thread_id_fkey foreign key (thread_id) references threads (id) on update cascade on delete cascade, constraint messages_user_id_fkey foreign key (user_id) references auth.users (id) on update cascade on delete cascade ); -create or replace view profile_threads as -select distinct on (m.thread_id) +CREATE OR REPLACE VIEW profile_threads AS +SELECT DISTINCT ON (m.thread_id) m.thread_id, m.message_id, m.user_id, m.created_at, t.thread_title, t.is_public, - u.raw_user_meta_data->>'avatar_url' as user_avatar_url -from + t.slug, + u.raw_user_meta_data->>'avatar_url' AS user_avatar_url +FROM public.messages m -join public.threads t on m.thread_id = t.id -join auth.users u on t.user_id = u.id -order by +JOIN public.threads t ON m.thread_id = t.id +JOIN auth.users u ON t.user_id = u.id +ORDER BY m.thread_id, - m.created_at asc; + m.created_at ASC;