feat: reorganize files and implement ui and sidebar

This commit is contained in:
shadcn 2023-06-11 00:23:23 +04:00
parent 2e80864b84
commit 01dc4520d6
36 changed files with 1347 additions and 462 deletions

View file

@ -1,7 +1,40 @@
'use server'
import { kv } from '@vercel/kv'
import { revalidatePath } from 'next/cache'
import { kv } from '@vercel/kv'
import { type Chat } from '@/lib/types'
export async function getChats(userId: string) {
try {
const pipeline = kv.pipeline()
const chats: string[] = await kv.zrange(`user:chat:${userId}`, 0, -1)
for (const chat of chats) {
pipeline.hgetall(chat)
}
const results = await pipeline.exec()
return results as Chat[]
} catch (error) {
return []
}
}
export async function getChat(id: string, userId: string) {
const chat = await kv.hgetall<Chat>(`chat:${id}`)
if (!chat) {
throw new Error('Not found')
}
if (userId && chat.userId !== userId) {
throw new Error('Unauthorized')
}
return chat
}
export async function removeChat({
id,