-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from birongliu/dev
Refactor chat components and update caching strategy
- Loading branch information
Showing
10 changed files
with
136 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use server'; | ||
|
||
import { revalidateTag } from "next/cache"; | ||
|
||
export default async function deleteRoomAction(id: string) { | ||
console.log("in delete room action") | ||
const url = `${process.env.NEXT_PUBLIC_API_URL}/api/rooms/${id}` | ||
const response = await fetch(url, { | ||
method: "DELETE", | ||
next: { tags: ["delete-rooms"] }, | ||
headers: { | ||
"Content-Type": "application/json" | ||
} | ||
}) | ||
const data = await response.json() | ||
revalidateTag("rooms") | ||
return data.acknowledged | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use server'; | ||
export default async function getUserFriend(username: string) { | ||
const fetchFriend = await fetch( | ||
`${process.env.NEXT_PUBLIC_API_URL}/api/users/${username}/friends`, | ||
{ | ||
method: "GET", | ||
cache: "force-cache", | ||
next: { tags: ["friends"] }, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
} | ||
); | ||
|
||
return fetchFriend; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use server'; | ||
|
||
export async function getUserRoom(id: string) { | ||
const fetchRoom = await fetch( | ||
`${process.env.NEXT_PUBLIC_API_URL}/api/rooms/${id}`, | ||
{ | ||
method: "GET", | ||
next: { tags: ["rooms"] }, | ||
cache: "force-cache", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
} | ||
); | ||
return fetchRoom; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use client' | ||
|
||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { useState } from 'react' | ||
|
||
export const ReactQueryClientProvider = ({ children }: { children: React.ReactNode }) => { | ||
const [queryClient] = useState( | ||
() => | ||
new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
// With SSR, we usually want to set some default staleTime | ||
// above 0 to avoid refetching immediately on the client | ||
staleTime: 60 * 1000, | ||
}, | ||
}, | ||
}) | ||
) | ||
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters