File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import Elysia from "elysia";
33import { nanoid } from "nanoid" ;
44import { authMiddleware } from "./auth" ;
55import z from "zod" ;
6+ import { realtime } from "@/lib/realtime" ;
67
78const ROOM_TTL_SECONDS = 10 * 60 ;
89
@@ -27,4 +28,19 @@ export const rooms = new Elysia({ prefix: "/room" })
2728 return { ttl : ttl > 0 ? ttl : 0 } ;
2829 } ,
2930 { query : z . object ( { roomId : z . string ( ) } ) } ,
31+ )
32+ . delete (
33+ "/" ,
34+ async ( { auth } ) => {
35+ await realtime
36+ . channel ( auth . roomId )
37+ . emit ( "chat.destroy" , { isDestroyed : true } ) ;
38+
39+ await Promise . all ( [
40+ redis . del ( auth . roomId ) ,
41+ redis . del ( `meta:${ auth . roomId } ` ) ,
42+ redis . del ( `messages:${ auth . roomId } ` ) ,
43+ ] ) ;
44+ } ,
45+ { query : z . object ( { roomId : z . string ( ) } ) } ,
3046 ) ;
Original file line number Diff line number Diff line change @@ -7,5 +7,6 @@ const app = new Elysia({ prefix: "/api" }).use(rooms).use(messages);
77
88export const GET = app . fetch ;
99export const POST = app . fetch ;
10+ export const DELETE = app . fetch ;
1011
1112export type App = typeof app ;
Original file line number Diff line number Diff line change 11import { useRoomStore } from "@/app/store/roomStore" ;
2+ import { useDeleteRoom } from "@/hooks/useDeleteRoom" ;
23import { useGetRemainingTime } from "@/hooks/useGetRemainingTime" ;
34import { useState } from "react" ;
45
@@ -12,6 +13,7 @@ export const RoomHeader = () => {
1213 const roomId = useRoomStore ( ( state ) => state . roomId ) ;
1314 const { timeRemaining } = useGetRemainingTime ( roomId ) ;
1415 const [ copyStatus , setCopyStatus ] = useState < "copy" | "copied" > ( "copy" ) ;
16+ const { destroyRoom } = useDeleteRoom ( ) ;
1517
1618 const copyLink = ( ) => {
1719 navigator . clipboard . writeText ( `${ window . location . origin } /room/${ roomId } ` ) ;
@@ -22,10 +24,6 @@ export const RoomHeader = () => {
2224 } , 2000 ) ;
2325 } ;
2426
25- const destroyRoom = ( ) => {
26- // TODO: Implement destroy room
27- } ;
28-
2927 return (
3028 < header className = "flex items-center justify-between border-b border-zinc-800 bg-zinc-900/30 p-4" >
3129 < div className = "flex items-center gap-4" >
@@ -63,7 +61,7 @@ export const RoomHeader = () => {
6361 </ div >
6462
6563 < button
66- onClick = { ( ) => destroyRoom ( ) }
64+ onClick = { ( ) => destroyRoom ( roomId ) }
6765 className = "group flex items-center gap-2 rounded bg-zinc-800 px-3 py-1.5 text-xs font-bold text-zinc-400 transition-all hover:bg-red-600 hover:text-white disabled:opacity-50"
6866 >
6967 < span className = "group-hover:animate-pulse" > 💣</ span >
Original file line number Diff line number Diff line change 1+ import { client } from "@/lib/client" ;
2+ import { useMutation } from "@tanstack/react-query" ;
3+
4+ export const useDeleteRoom = ( ) => {
5+ const { mutate : destroyRoom } = useMutation ( {
6+ mutationFn : async ( roomId : string ) => {
7+ await client . room . delete ( null , { query : { roomId } } ) ;
8+ } ,
9+ } ) ;
10+ return { destroyRoom } ;
11+ } ;
You can’t perform that action at this time.
0 commit comments