mirror of
https://github.com/supabase/supabase.git
synced 2026-10-19 16:19:10 +03:00
Add recently generated section
This commit is contained in:
1 parent
efdfd1c420
commit
e6c47efcb0
12 files changed
+138
-33
No files matched your search
@@ -1,5 +1,4 @@
|
||||
import { stripIndent } from 'common-tags'
|
||||
import { cookies } from 'next/headers'
|
||||
import OpenAI from 'openai'
|
||||
|
||||
// import is weird, what's up with this?
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
import { cookies } from 'next/headers'
|
||||
|
||||
import { cache } from 'react'
|
||||
|
||||
export const getMessages = cache(async (thread_id: string) => {
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
import { Message } from 'ai'
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { cookies } from 'next/headers'
|
||||
import { redirect } from 'next/navigation'
|
||||
|
||||
import { z } from 'zod'
|
||||
@@ -233,8 +232,7 @@ export async function updateThreadName(prevState: any, formData: FormData) {
|
||||
}
|
||||
}
|
||||
export async function updateThreadVisibility(prevState: any, formData: FormData) {
|
||||
const cookieStore = cookies()
|
||||
const supabase = createClient(cookieStore)
|
||||
const supabase = createClient()
|
||||
|
||||
try {
|
||||
const schema = z.object({
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { cookies } from 'next/headers'
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
|
||||
export async function GET(request: Request) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
import { Database } from '@/types/supabase'
|
||||
import { cookies } from 'next/headers'
|
||||
import EmptyState from './EmptyState'
|
||||
import Thread from './Thread'
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
import { default as dayjs, default as relativeTime } from 'dayjs'
|
||||
import { cookies } from 'next/headers'
|
||||
import { redirect } from 'next/navigation'
|
||||
import Threads from './Threads'
|
||||
import { Suspense } from 'react'
|
||||
@@ -12,11 +11,6 @@ export const metadata: Metadata = {
|
||||
title: 'database.design | Profile',
|
||||
}
|
||||
|
||||
// revalidatePath not working in the create route handler
|
||||
// force-dynamic to refetch every time if needed
|
||||
// just a hack for now
|
||||
// export const dynamic = 'force-dynamic'
|
||||
|
||||
const Profile = async () => {
|
||||
return (
|
||||
<div className="grid grid-cols-4 gap-x-8 py-6 xl:py-12 gap-y-6 xl:gap-y-0">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Button } from '@ui/components/Button'
|
||||
import { Github } from 'lucide-react'
|
||||
import { cookies, headers } from 'next/headers'
|
||||
import { headers } from 'next/headers'
|
||||
import { redirect } from 'next/navigation'
|
||||
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
import { User2 } from 'lucide-react'
|
||||
import { cookies } from 'next/headers'
|
||||
import { Suspense } from 'react'
|
||||
import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from 'ui'
|
||||
import AvatarDropdown from './AvatarDropdown'
|
||||
|
||||
@@ -1,8 +1,49 @@
|
||||
const RecentlyGenerated = () => {
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
import Image from 'next/image'
|
||||
import { Suspense } from 'react'
|
||||
import { GenericSkeletonLoader } from './Shimmer'
|
||||
import Link from 'next/link'
|
||||
const RecentlyGenerated = async () => {
|
||||
const supabase = createClient()
|
||||
const { data: threads } = await supabase
|
||||
.from('profile_threads')
|
||||
.select()
|
||||
.eq('is_public', true)
|
||||
.order('created_at', { ascending: false })
|
||||
|
||||
// @todo
|
||||
// these probably need to be picked randomly somehow so
|
||||
// the same user doesn't show up every time if they've
|
||||
// generated a bunch of threads
|
||||
|
||||
return (
|
||||
<div className="mt-8">
|
||||
<h2>Recently generated</h2>
|
||||
<p>show from previous day to give ppl time to make their generation private</p>
|
||||
<Suspense fallback={<GenericSkeletonLoader />}>
|
||||
<div className="container max-w-4xl mx-auto">
|
||||
<ul className="grid gap-4 grid-cols-3">
|
||||
{threads?.map((thread) => (
|
||||
<li key={thread.thread_id}>
|
||||
<Link
|
||||
href={`${thread.thread_id}/${thread.message_id}`}
|
||||
className="flex items-center gap-2 py-2 px-4 border rounded-xl"
|
||||
>
|
||||
{thread.user_avatar_url && (
|
||||
<Image
|
||||
alt="avatar"
|
||||
src={thread.user_avatar_url}
|
||||
width={24}
|
||||
height={24}
|
||||
className="rounded-full"
|
||||
/>
|
||||
)}
|
||||
<span className="truncate">{thread.thread_title}</span>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</Suspense>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
images: {
|
||||
remotePatterns: [
|
||||
{
|
||||
protocol: 'https',
|
||||
hostname: 'avatars.githubusercontent.com',
|
||||
port: '',
|
||||
},
|
||||
],
|
||||
},
|
||||
transpilePackages: ['ui', 'ui-patterns'],
|
||||
webpack: (config, { dev, isServer, webpack, nextRuntime }) => {
|
||||
config.module.rules.push({
|
||||
|
||||
@@ -21,20 +21,20 @@ 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)
|
||||
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
|
||||
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
|
||||
m.thread_id,
|
||||
m.created_at asc;
|
||||
|
||||
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
|
||||
|
||||
FROM
|
||||
public.messages m
|
||||
JOIN public.threads t ON m.thread_id = t.id
|
||||
ORDER BY
|
||||
m.thread_id,
|
||||
m.created_at ASC;
|
||||
@@ -48,6 +48,20 @@ export interface Database {
|
||||
referencedRelation: "threads"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "messages_thread_id_fkey"
|
||||
columns: ["thread_id"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "threads_with_avatars"
|
||||
referencedColumns: ["thread_id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "messages_thread_id_fkey"
|
||||
columns: ["thread_id"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "threads_with_emails"
|
||||
referencedColumns: ["thread_id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "messages_user_id_fkey"
|
||||
columns: ["user_id"]
|
||||
@@ -98,6 +112,7 @@ export interface Database {
|
||||
message_id: string | null
|
||||
thread_id: string | null
|
||||
thread_title: string | null
|
||||
user_avatar_url: string | null
|
||||
user_id: string | null
|
||||
}
|
||||
Relationships: [
|
||||
@@ -108,6 +123,20 @@ export interface Database {
|
||||
referencedRelation: "threads"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "messages_thread_id_fkey"
|
||||
columns: ["thread_id"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "threads_with_avatars"
|
||||
referencedColumns: ["thread_id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "messages_thread_id_fkey"
|
||||
columns: ["thread_id"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "threads_with_emails"
|
||||
referencedColumns: ["thread_id"]
|
||||
},
|
||||
{
|
||||
foreignKeyName: "messages_user_id_fkey"
|
||||
columns: ["user_id"]
|
||||
@@ -117,6 +146,44 @@ export interface Database {
|
||||
}
|
||||
]
|
||||
}
|
||||
threads_with_avatars: {
|
||||
Row: {
|
||||
created_at: string | null
|
||||
is_public: boolean | null
|
||||
thread_id: string | null
|
||||
thread_title: string | null
|
||||
user_avatar_url: string | null
|
||||
user_id: string | null
|
||||
}
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: "threads_user_id_fkey"
|
||||
columns: ["user_id"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "users"
|
||||
referencedColumns: ["id"]
|
||||
}
|
||||
]
|
||||
}
|
||||
threads_with_emails: {
|
||||
Row: {
|
||||
created_at: string | null
|
||||
is_public: boolean | null
|
||||
thread_id: string | null
|
||||
thread_title: string | null
|
||||
user_email: string | null
|
||||
user_id: string | null
|
||||
}
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: "threads_user_id_fkey"
|
||||
columns: ["user_id"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "users"
|
||||
referencedColumns: ["id"]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Functions: {
|
||||
[_ in never]: never
|
||||
|
||||
Reference in new issue
Block a user