From e668eab53c1b0b1edd9c727d409bbd2bed20ecdb Mon Sep 17 00:00:00 2001 From: Redskull-127 Date: Sat, 27 Jul 2024 04:18:58 +0530 Subject: [PATCH] refactor: Remove commented out code and optimize LiveCount component --- components/live-count.tsx | 11 -- lib/client/functions/chromecast.tsx | 65 +++++++---- lib/client/functions/settings.tsx | 162 ++++++++++++++++------------ 3 files changed, 140 insertions(+), 98 deletions(-) diff --git a/components/live-count.tsx b/components/live-count.tsx index ce439be..8c50822 100644 --- a/components/live-count.tsx +++ b/components/live-count.tsx @@ -19,17 +19,6 @@ export default function LiveCount() { }, []); if (!activeUsers) return null; if (activeUsers === 0) return null; - // return ( - // - // ); return ( {activeUsers} Live {activeUsers === 1 ? 'User' : 'Users'} diff --git a/lib/client/functions/chromecast.tsx b/lib/client/functions/chromecast.tsx index 8e28147..12052ab 100644 --- a/lib/client/functions/chromecast.tsx +++ b/lib/client/functions/chromecast.tsx @@ -11,6 +11,12 @@ import { DialogHeader, DialogTitle, } from '@/components/ui/dialog'; +import { + Tooltip, + TooltipContent, + TooltipProvider, + TooltipTrigger, +} from '@/components/ui/tooltip'; import { useState, useRef } from 'react'; import { toast } from 'sonner'; @@ -64,11 +70,26 @@ export default function ChromeCast() { ); toast.promise(connectPromise, { - loading: 'Loading...', + loading: ( +
+

Connecting to device...

+ +
+ ), success: (data: any) => { return `${data.name} connected successfully!\n Now Playing ${castDetails.title}!`; }, - error: 'Error', + error: 'Something went wrong!', }); castRef.current.on('disconnect', () => { @@ -82,19 +103,28 @@ export default function ChromeCast() { return ( <> - + + + + + + +

Cast to chromecast enabled devices!

+
+
+
{dPad && } ); @@ -126,8 +156,3 @@ export const ShowControls = () => { ); }; - -function test() { - const casttest = new Castjs(); - casttest._isConnectedChanged(); -} diff --git a/lib/client/functions/settings.tsx b/lib/client/functions/settings.tsx index ab64a85..f26d2fc 100644 --- a/lib/client/functions/settings.tsx +++ b/lib/client/functions/settings.tsx @@ -29,7 +29,7 @@ import { Bell, } from 'lucide-react'; import { signIn, signOut, useSession } from 'next-auth/react'; -import { useEffect, useRef } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { toast } from 'sonner'; import { CommandDialogBox } from '@/lib/commandbar/commandnew'; import ChromeCast from './chromecast'; @@ -43,9 +43,14 @@ export type SettingsProps = { }; export function Settings(params: SettingsProps) { + const [isHydrated, setIsHydrated] = useState(false); const { status, data: session } = useSession(); const notificationRef = useRef(null); + useEffect(() => { + setIsHydrated(true); + }, []); + useEffect(() => { if (!window.localStorage.getItem('notificationSound')) { window.localStorage.setItem('notificationSound', 'low'); @@ -96,52 +101,66 @@ export function Settings(params: SettingsProps) {
- - - + + + User Action Center! + + + + + + + {status === 'authenticated' + ? session.user?.name + : 'Action Required'} + + {status === 'authenticated' ? ( - user + { + signOut(); + }} + > + Sign Out + ) : ( - + { + signIn('google'); + }} + > + Log in + )} - - - - - {status === 'authenticated' - ? session.user?.name - : 'Action Required'} - - - {status === 'authenticated' ? ( - { - signOut(); - }} - > - Sign Out - - ) : ( - { - signIn('google'); - }} - > - Log in - - )} - - + + + )} @@ -189,29 +208,38 @@ export function Settings(params: SettingsProps) { - + + + + + + +

Change message notification sound!

+
+
+