diff --git a/packages/desktop/src/components/ProtectedRoute/index.tsx b/packages/desktop/src/components/ProtectedRoute/index.tsx index 2a26b00..1733791 100644 --- a/packages/desktop/src/components/ProtectedRoute/index.tsx +++ b/packages/desktop/src/components/ProtectedRoute/index.tsx @@ -20,6 +20,7 @@ export default function ProtectedRoute({ isLoading: serverLoading, isSuccess: isServerHealthy, error: serverStatusError, + isFetching: serverFetching, } = useServerCheck(); const { isLoading, isError, isFetching, isSuccess, refetch } = useAuthCheck( @@ -59,6 +60,7 @@ export default function ProtectedRoute({ refetch(); }, [jwtToken]); + // first time loading if (serverLoading) return ( diff --git a/packages/desktop/src/controller/index.tsx b/packages/desktop/src/controller/index.tsx index 5892e06..9ae37fc 100644 --- a/packages/desktop/src/controller/index.tsx +++ b/packages/desktop/src/controller/index.tsx @@ -57,7 +57,11 @@ export function useUserLines() { // todo: base/source of truth for getting all of the lines for the user // merge with sockets + audio clip data + master data + convomember data - return useQuery("USER_LINES", ApiCalls.getUserLines); + return useQuery("USER_LINES", ApiCalls.getUserLines, { + refetchOnWindowFocus: false, + refetchIntervalInBackground: false, + staleTime: Infinity, + }); } // =========== MUTATIONS diff --git a/packages/desktop/src/controller/lineDataProvider.tsx b/packages/desktop/src/controller/lineDataProvider.tsx index bd74874..2626c2b 100644 --- a/packages/desktop/src/controller/lineDataProvider.tsx +++ b/packages/desktop/src/controller/lineDataProvider.tsx @@ -174,8 +174,9 @@ function useSocketHandler(linesData: MasterLineData[]) { * and doing initial connections/tune ins ?could trigger this later? */ useEffect(() => { - console.log(linesData); - if (linesData) { + if (linesData?.length > 0) { + console.log("going to make initial connections and create lines map"); + setLinesMap((prevMappings) => { // go through the lines from the persistent store @@ -282,17 +283,14 @@ function useSocketHandler(linesData: MasterLineData[]) { [$ws] ); + // TODO: move all of these emitters to just having child views doing the work here return { linesMap, - emitters: $ws - ? { - handleConnectToLine, - handleTuneToLine, - handleStartBroadcast, - handleStopBroadcast, - handleFetchMoreAudioBlocks, - } - : {}, + handleConnectToLine, + handleTuneToLine, + handleStartBroadcast, + handleStopBroadcast, + handleFetchMoreAudioBlocks, }; } @@ -303,11 +301,17 @@ interface ILineDataContext { // represents the modified and up to date lines data with availability from session linesMap: LineIdToMasterLine; relevantUsers: User[]; + + // in case some components need this like in the peer handling + $ws: Socket; } -const LineDataContext = React.createContext({ +const LineDataContext = React.createContext< + Partial> +>({ linesMap: {}, relevantUsers: [], + $ws: undefined, }); export function LineDataProvider({ children }) { @@ -318,11 +322,19 @@ export function LineDataProvider({ children }) { // ?just do simple synchronous axios/fetch in useEffect and manage isLoading ourselves? const { data: basicUserLinesData } = useUserLines(); - const { linesMap } = useSocketHandler(basicUserLinesData?.data?.masterLines); + const { linesMap, ...handlers } = useSocketHandler( + basicUserLinesData?.data?.masterLines + ); - const value: ILineDataContext = { + if (!$ws) { + return attempting to connect you for the here and now...; + } + + const value: ILineDataContext & ReturnType = { linesMap, // TODO send the updated map instead of this array relevantUsers: [], + $ws, + ...handlers, }; return ( diff --git a/packages/desktop/src/pages/terminal/details/index.tsx b/packages/desktop/src/pages/terminal/details/index.tsx index 05faec0..6bf60c1 100644 --- a/packages/desktop/src/pages/terminal/details/index.tsx +++ b/packages/desktop/src/pages/terminal/details/index.tsx @@ -16,6 +16,8 @@ export default function LineDetailsTerminal({ }: { selectedLine: MasterLineData; }) { + const { handleTuneToLine } = useLineDataProvider(); + const { data: userDetails } = useGetUserDetails(); const isUserToggleTuned = useMemo( () => selectedLine?.currentUserMember?.state === LineMemberState.TUNED, @@ -59,6 +61,10 @@ export default function LineDetailsTerminal({ className="absolute bottom-0 p-4 shadow-2xl flex flex-row items-center gap-2 justify-end w-full" > + {`${ + selectedLine?.tunedInMemberIds?.length ?? 0 + } on the line`} + diff --git a/packages/desktop/src/pages/terminal/index.tsx b/packages/desktop/src/pages/terminal/index.tsx index 979afb1..bd301e5 100644 --- a/packages/desktop/src/pages/terminal/index.tsx +++ b/packages/desktop/src/pages/terminal/index.tsx @@ -26,6 +26,12 @@ export default function NirvanaTerminal() { const { isLoading: isLoadingInitialLines } = useUserLines(); const { linesMap } = useLineDataProvider(); + useEffect(() => { + console.log("change/update in lines map"); + + console.log(linesMap); + }, [linesMap]); + const allLines: MasterLineData[] = useMemo(() => { const masterLines: MasterLineData[] = Object.values(linesMap); diff --git a/packages/desktop/src/styles/index.css b/packages/desktop/src/styles/index.css index 593870f..f1ff165 100644 --- a/packages/desktop/src/styles/index.css +++ b/packages/desktop/src/styles/index.css @@ -28,12 +28,12 @@ body { } /* TODO: temporary...remove? later? */ -body { +/* body { -webkit-user-select: none; -webkit-app-region: drag; cursor: pointer; -} +} */ .titlebar-button { -webkit-app-region: no-drag;