From 5e0d04f2b3420d78d71834618e145ef9ef6c8563 Mon Sep 17 00:00:00 2001 From: Irere123 Date: Mon, 19 Aug 2024 18:02:32 +0200 Subject: [PATCH] fix(web): currentConf minimized card controller --- api/lib/telescope/mutations/confs.ex | 2 +- apps/web/src/app/c/[slug]/page.tsx | 8 +- apps/web/src/components/RightBlock.tsx | 17 +++++ .../src/components/room/MinimizedRoomCard.tsx | 74 +++++++++++++++++++ .../room/MinimizedRoomCardController.tsx | 63 ++++++++++++++++ .../web/src/webrtc/components/AudioRender.tsx | 2 +- 6 files changed, 161 insertions(+), 5 deletions(-) create mode 100644 apps/web/src/components/RightBlock.tsx create mode 100644 apps/web/src/components/room/MinimizedRoomCard.tsx create mode 100644 apps/web/src/components/room/MinimizedRoomCardController.tsx diff --git a/api/lib/telescope/mutations/confs.ex b/api/lib/telescope/mutations/confs.ex index 319583e..1c1364d 100644 --- a/api/lib/telescope/mutations/confs.ex +++ b/api/lib/telescope/mutations/confs.ex @@ -77,7 +77,7 @@ defmodule Telescope.Mutations.Confs do if( length(conf.people_preview_list) < 8 or - not is_nil(Enum.find(conf.people_preview_list, &(&1.id === user_id))) + is_nil(Enum.find(conf.people_preview_list, &(&1.id === user_id))) ) do list = [ diff --git a/apps/web/src/app/c/[slug]/page.tsx b/apps/web/src/app/c/[slug]/page.tsx index c16e213..f1ab09d 100644 --- a/apps/web/src/app/c/[slug]/page.tsx +++ b/apps/web/src/app/c/[slug]/page.tsx @@ -1,10 +1,12 @@ +import { MainLayout } from "@spek/ui"; +import { Metadata, ResolvingMetadata } from "next"; + import { baseUrl } from "@/utils/constants"; import { defaultQueryFn } from "@/utils/defaultQueryFn"; -import { Metadata, ResolvingMetadata } from "next"; import { CommunityPageController } from "./controller"; -import { MainLayout } from "@spek/ui"; import { LeftPanel } from "@/components/Panels"; import { WaitForWsAndAuth } from "@/components/auth/WaitForWsAndAuth"; +import { RightBlock } from "@/components/RightBlock"; type Props = { params: { slug: string }; @@ -47,7 +49,7 @@ export async function generateMetadata( export default async function CommunityPage({ params }: Props) { return ( - }> + } rightPanel={}> diff --git a/apps/web/src/components/RightBlock.tsx b/apps/web/src/components/RightBlock.tsx new file mode 100644 index 0000000..4a7241f --- /dev/null +++ b/apps/web/src/components/RightBlock.tsx @@ -0,0 +1,17 @@ +"use client"; + +import { useCurrentConfIdStore } from "@/stores/useCurentConfIdStore"; +import React from "react"; +import { MinimizedRoomCardController } from "./room/MinimizedRoomCardController"; + +export const RightBlock: React.FC = () => { + const { currentConfId } = useCurrentConfIdStore(); + + return ( +
+ {currentConfId ? ( + + ) : null} +
+ ); +}; diff --git a/apps/web/src/components/room/MinimizedRoomCard.tsx b/apps/web/src/components/room/MinimizedRoomCard.tsx new file mode 100644 index 0000000..36ff20d --- /dev/null +++ b/apps/web/src/components/room/MinimizedRoomCard.tsx @@ -0,0 +1,74 @@ +import { Button, Icon } from "@spek/ui"; + +interface MinimizedRoomCardProps { + onFullScreenClick: () => void; + leaveLoading?: boolean; + room: { + name: string; + descriptioin: string; + me: { + isSpeaker: boolean; + isMuted: boolean; + isDeafened: boolean; + switchMuted: () => void; + switchDeafened: () => void; + leave: () => void; + }; + }; +} + +export const MinimizedRoomCard: React.FC = ({ + onFullScreenClick, + room, + leaveLoading, +}) => { + return ( +
+
+

+ {room.name} +

+

+ {room.descriptioin} +

+
+
+
+
+ {room.me.isMuted ? : } +
+ +
+ {room.me.isDeafened ? ( + + ) : ( + + )} +
+ +
+ +
+
+ +
+
+ ); +}; diff --git a/apps/web/src/components/room/MinimizedRoomCardController.tsx b/apps/web/src/components/room/MinimizedRoomCardController.tsx new file mode 100644 index 0000000..8435db5 --- /dev/null +++ b/apps/web/src/components/room/MinimizedRoomCardController.tsx @@ -0,0 +1,63 @@ +"use client"; +import { useRouter } from "next/navigation"; + +import { useConn } from "@/hooks/useConn"; +import { MinimizedRoomCard } from "./MinimizedRoomCard"; +import { useMuteStore } from "@/stores/useMuteStore"; +import { useDeafStore } from "@/stores/useDeafStore"; +import { useSetMute } from "@/hooks/useSetMute"; +import { useSetDeafen } from "@/hooks/useSetDeafen"; +import { useLeaveConf } from "@/hooks/useLeaveConf"; +import { useTypeSafeQuery } from "@/hooks/useTypeSafeQuery"; + +interface Props { + confId: string; +} + +export const MinimizedRoomCardController: React.FC = ({ confId }) => { + const { user } = useConn(); + const { muted } = useMuteStore(); + const { deafened } = useDeafStore(); + const setMute = useSetMute(); + const setDeafen = useSetDeafen(); + const { isLoading, leaveConf } = useLeaveConf(); + const { push } = useRouter(); + const { isLoading: joinLoading, data } = useTypeSafeQuery( + ["joinConfAndGetInfo", confId], + {}, + [confId] + ); + + if (joinLoading || !data) { + return null; + } + + if ("error" in data) { + return
{data.error}
; + } + + return ( + <> + {user ? ( +
+ push(`/conf/${data.conf.id}`)} + leaveLoading={isLoading} + room={{ + me: { + isDeafened: deafened, + isMuted: muted, + leave: () => leaveConf(), + isSpeaker: true, + switchDeafened: () => setDeafen(!deafened), + switchMuted: () => setMute(!muted), + }, + name: data?.conf.name, + descriptioin: data?.conf.description, + }} + /> +
+ ) : null} + + ); +}; diff --git a/apps/web/src/webrtc/components/AudioRender.tsx b/apps/web/src/webrtc/components/AudioRender.tsx index faf3812..77fa530 100644 --- a/apps/web/src/webrtc/components/AudioRender.tsx +++ b/apps/web/src/webrtc/components/AudioRender.tsx @@ -77,7 +77,7 @@ export const AudioRender: React.FC = () => { setAudioRef(k, a); audioRefs.current.push([k, a]); a.srcObject = new MediaStream([consumer.track]); - // prevent modal from showing up more than once in a single render cycle + // prevent modal from showing up more than once in a single render cycle const notAllowedErrorContent = notAllowedErrorCountRef.current; a.play().catch((err) => {