TIL

2024.04.02 TIL #์ฑ„ํŒ…์ฐฝ ๋งŒ๋“ค๊ธฐ #Supabse_realtime

inz1234 2024. 5. 2. 16:04

๐Ÿ“Œ Task TODOLIST

- [x] ์ฑ„ํŒ…๋ฐฉ ๋ผˆ๋Œ€ ๋งŒ๋“ค๊ธฐ 

- [x]  ์ด์ „ ์ฑ„ํŒ… ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ

- [x] ์ƒˆ๋กœ๊ณ ์นจ ์‹œ์—๋„ ๋ฐ์ดํ„ฐ ์œ ์ง€ํ•˜์—ฌ ๋ Œ๋”๋งํ•˜๊ธฐ

- [x] ์ฑ„ํŒ… ๋ฐ์ดํ„ฐ ์ƒˆ๋กœ ์ถ”๊ฐ€ํ•˜๊ธฐ

 

โœจ ๊ฐœ๋ฐœ ๋‚ด์šฉ

์ฑ„ํŒ…๋ฐฉ ๋ผˆ๋Œ€ ๋งŒ๋“ค๊ธฐ

 

์ด์ „ ์ฑ„ํŒ… ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ

- TTV๋ฅผ ์œ„ํ•ด์„œ server ์ธก supabase ์‚ฌ์šฉํ•˜์—ฌ CSR ์ปดํฌ๋„ŒํŠธ์— Props๋กœ ๋‚ด๋ ค์ฃผ๊ธฐ

- ์ฑ„ํŒ… ๋ฐ์ดํ„ฐ๋ฅผ CSR ์ปดํฌ๋„ŒํŠธ์—์„œ ์ง์ ‘ ๋ถˆ๋Ÿฌ์™€์„œ ๋ Œ๋”๋ง ํ•  ์ˆ˜๋„ ์žˆ์—ˆ์ง€๋งŒ,

  TTV๋ฅผ ์ค„์ด๊ธฐ ์œ„ํ•ด ์ดˆ๊ธฐ ๋ฉ”์„ธ์ง€๋Š” ์„œ๋ฒ„์—์„œ ๋ฐ›์•„์„œ CSR ์ปดํฌ๋„ŒํŠธ๋กœ Props๋กœ ๋„˜๊ฒจ์คฌ๋‹ค.

const ChatPage = async ({ params }: { params: { chatroom_id: string } }) => {
  const chatRoomId = params.chatroom_id;
  const supabase = serverSupabase();
  const {
    data: { user }
  } = await supabase.auth.getUser();
  const { from, to } = getFromTo(0, ITEM_INTERVAL);
  const { data: allMsgs } = await supabase
    .from('messages')
    .select('*')
    .eq('chatting_room_id', chatRoomId)
    .range(from, to)
    .order('created_at', { ascending: false });

  return (
    <Suspense fallback={<ChatLoading />}>
      <div className="relative flex flex-row">
        <InitChat user={user} chatRoomId={chatRoomId} allMsgs={allMsgs ?? []} /> ---> ์ด ๋ถ€๋ถ„
        <div className="flex lg:flex-row lg:w-full max-sm:w-full max-sm:flex-col justify-center mx-auto">
          <div className="lg:flex lg:max-w-96 max-sm:absolute max-sm:z-50 max-sm:bg-white ">
            <SideBar chatRoomId={chatRoomId} />
          </div>

 

Supabase-realtime์œผ๋กœ ์ฑ„๋„ ๊ตฌ๋…ํ•˜๊ธฐ

 

์ƒˆ๋กœ๊ณ ์นจ ์‹œ์—๋„ ๋ฐ์ดํ„ฐ ์œ ์ง€ํ•˜๊ธฐ

- ์ƒˆ๋กœ๊ณ ์นจ ์‹œ ์„œ๋ฒ„์— ์ง์ ‘ ์š”์ฒญํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์•„์˜ค๋Š” ๊ฒƒ๊ณผ, useQuery๋กœ ํ˜ธ์ถœํ•˜์—ฌ ๋ฐ›์•„์˜ค๋Š” ๊ฒƒ ์ค‘ ๊ณ ๋ฏผ์ด๋‹ค.

- ์„ฑ๋Šฅ์ ์œผ๋กœ๋Š” ์–ด์ฐจํ”ผ ํ˜ธ์ถœ์ด ๊ฐ€๋Šฅ ๊ฒƒ์€ ๋งคํ•œ๊ฐ€์ง€์—ฌ์„œ ํฐ ์ฐจ์ด๋Š” ์—†์„ ๋“ฏํ•œ๋ฐ, ์ข€ ๋” ๊ณ ๋ฏผํ•ด๋ด์•ผ๊ฒ ๋‹ค.

 

์ฑ„ํŒ… ์ถ”๊ฐ€ํ•˜๊ธฐ