Skip to content

Commit

Permalink
refactor(apps/phone): notification ui
Browse files Browse the repository at this point in the history
  • Loading branch information
itschip committed Jan 27, 2024
1 parent 8fd8ed3 commit db6e3ab
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 287 deletions.
233 changes: 126 additions & 107 deletions apps/phone/src/Phone.tsx
Original file line number Diff line number Diff line change
@@ -1,130 +1,149 @@
import React, { Dispatch, Fragment, SetStateAction, useEffect } from 'react';
import React, {Dispatch, Fragment, SetStateAction, useEffect} from 'react';
import './Phone.css';
import { Route } from 'react-router-dom';
import { CallModal } from '@os/call/components/CallModal';
import { HomeApp } from './apps/home/components/Home';
import { NotificationBar } from '@os/new-notifications/components/NotificationBar';
import { Navigation } from '@os/navigation-bar/components/Navigation';
import { useSimcardService } from '@os/simcard/hooks/useSimcardService';
import { usePhoneService } from '@os/phone/hooks/usePhoneService';
import { useApps } from '@os/apps/hooks/useApps';
import { useTwitterService } from './apps/twitter/hooks/useTwitterService';
import { useMarketplaceService } from './apps/marketplace/hooks/useMarketplaceService';
import { useMessagesService } from './apps/messages/hooks/useMessageService';
import { useSettings } from './apps/settings/hooks/useSettings';
import { useCallService } from '@os/call/hooks/useCallService';
import { useDialService } from './apps/dialer/hooks/useDialService';
import { useMatchService } from './apps/match/hooks/useMatchService';
import {Route} from 'react-router-dom';
import {CallModal} from '@os/call/components/CallModal';
import {HomeApp} from './apps/home/components/Home';
import {NotificationBar} from '@os/new-notifications/components/NotificationBar';
import {Navigation} from '@os/navigation-bar/components/Navigation';
import {useSimcardService} from '@os/simcard/hooks/useSimcardService';
import {usePhoneService} from '@os/phone/hooks/usePhoneService';
import {useApps} from '@os/apps/hooks/useApps';
import {useTwitterService} from './apps/twitter/hooks/useTwitterService';
import {useMarketplaceService} from './apps/marketplace/hooks/useMarketplaceService';
import {useMessagesService} from './apps/messages/hooks/useMessageService';
import {useSettings} from './apps/settings/hooks/useSettings';
import {useCallService} from '@os/call/hooks/useCallService';
import {useDialService} from './apps/dialer/hooks/useDialService';
import {useMatchService} from './apps/match/hooks/useMatchService';
import InjectDebugData from './os/debug/InjectDebugData';
import { NotificationAlert } from '@os/notifications/components/NotificationAlert';
import { useCallModal } from '@os/call/hooks/useCallModal';
import {NotificationAlert} from '@os/notifications/components/NotificationAlert';
import {useCallModal} from '@os/call/hooks/useCallModal';
import WindowSnackbar from './ui/components/WindowSnackbar';
import { useTranslation } from 'react-i18next';
import { PhoneEvents } from '@typings/phone';
import {useTranslation} from 'react-i18next';
import {PhoneEvents} from '@typings/phone';
import PhoneWrapper from './PhoneWrapper';
import DefaultConfig from '../../../config.default.json';
import { TopLevelErrorComponent } from '@ui/components/TopLevelErrorComponent';
import { useConfig } from '@os/phone/hooks/useConfig';
import { useContactsListener } from './apps/contacts/hooks/useContactsListener';
import { useNoteListener } from './apps/notes/hooks/useNoteListener';
import { PhoneSnackbar } from '@os/snackbar/components/PhoneSnackbar';
import { useInvalidSettingsHandler } from './apps/settings/hooks/useInvalidSettingsHandler';
import { useKeyboardService } from '@os/keyboard/hooks/useKeyboardService';
import { useExternalApps } from '@common/hooks/useExternalApps';
import { useTheme } from '@mui/material';
import { useDarkchatService } from './apps/darkchat/hooks/useDarkchatService';
import { useNotificationListener } from '@os/new-notifications/useNotificationListener';
import { useSystemNotificationListener } from '@os/new-notifications/components/system/useSystemNotificationListener';
import { useNotificationBarListener } from '@os/new-notifications/useNotificationBarListener';
import {TopLevelErrorComponent} from '@ui/components/TopLevelErrorComponent';
import {useConfig} from '@os/phone/hooks/useConfig';
import {useContactsListener} from './apps/contacts/hooks/useContactsListener';
import {useNoteListener} from './apps/notes/hooks/useNoteListener';
import {PhoneSnackbar} from '@os/snackbar/components/PhoneSnackbar';
import {useInvalidSettingsHandler} from './apps/settings/hooks/useInvalidSettingsHandler';
import {useKeyboardService} from '@os/keyboard/hooks/useKeyboardService';
import {useExternalApps} from '@common/hooks/useExternalApps';
import {useTheme} from '@mui/material';
import {useDarkchatService} from './apps/darkchat/hooks/useDarkchatService';
import {useNotificationListener} from '@os/new-notifications/useNotificationListener';
import {useSystemNotificationListener} from '@os/new-notifications/components/system/useSystemNotificationListener';
import {useNotificationBarListener} from '@os/new-notifications/useNotificationBarListener';
import {ActiveCall, CallEvents} from "@typings/call";
import {NotificationEvents, SystemNotificationDTO} from "@typings/notifications";

interface PhoneProps {
notiRefCB: Dispatch<SetStateAction<HTMLElement>>;
notiRefCB: Dispatch<SetStateAction<HTMLElement>>;
}

const Phone: React.FC<PhoneProps> = ({ notiRefCB }) => {
const { i18n } = useTranslation();
const Phone: React.FC<PhoneProps> = ({notiRefCB}) => {
const {i18n} = useTranslation();

const { apps } = useApps();
const [settings] = useSettings();
const theme = useTheme();
const {apps} = useApps();
const [settings] = useSettings();
const theme = useTheme();

// Set language from local storage
// This will only trigger on first mount & settings changes
useEffect(() => {
i18n.changeLanguage(settings.language.value).catch((e) => console.error(e));
}, [i18n, settings.language]);
// Set language from local storage
// This will only trigger on first mount & settings changes
useEffect(() => {
i18n.changeLanguage(settings.language.value).catch((e) => console.error(e));
}, [i18n, settings.language]);

useEffect(() => {
if (settings.theme.value === 'taso-dark') {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
}, [settings.theme.value]);
useEffect(() => {
if (settings.theme.value === 'taso-dark') {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
}, [settings.theme.value]);

useConfig();
useKeyboardService();
usePhoneService();
useSimcardService();
useNotificationListener();
useSystemNotificationListener();
useNotificationBarListener();
useTwitterService();
useMatchService();
useMarketplaceService();
useMessagesService();
useContactsListener();
useNoteListener();
useCallService();
useDialService();
useDarkchatService();
useInvalidSettingsHandler();
useConfig();
useKeyboardService();
usePhoneService();
useSimcardService();
useNotificationListener();
useSystemNotificationListener();
useNotificationBarListener();
useTwitterService();
useMatchService();
useMarketplaceService();
useMessagesService();
useContactsListener();
useNoteListener();
useCallService();
useDialService();
useDarkchatService();
useInvalidSettingsHandler();

const externalApps = useExternalApps();
const externalApps = useExternalApps();

const { modal: callModal } = useCallModal();
const {modal: callModal} = useCallModal();

return (
<div>
<TopLevelErrorComponent>
<WindowSnackbar />
<PhoneWrapper>
<NotificationBar />
<div className="PhoneAppContainer" id="notificationAppContainer" ref={notiRefCB}>
<>
<Route exact path="/" component={HomeApp} />
{callModal && <Route exact path="/call" component={CallModal} />}
{apps.map((App) => (
<Fragment key={App.id}>{!App.isDisabled && <App.Route key={App.id} />}</Fragment>
))}
return (
<div>
<TopLevelErrorComponent>
<WindowSnackbar/>
<PhoneWrapper>
<NotificationBar/>
<div className="PhoneAppContainer" id="notificationAppContainer" ref={notiRefCB}>
<>
<Route exact path="/" component={HomeApp}/>
{callModal && <Route exact path="/call" component={CallModal}/>}
{apps.map((App) => (
<Fragment key={App.id}>{!App.isDisabled && <App.Route key={App.id}/>}</Fragment>
))}

{externalApps.map((App) => (
<Fragment key={App.id}>
<App.Route settings={settings} i18n={i18n} theme={theme} />
</Fragment>
))}
</>
<NotificationAlert />
<PhoneSnackbar />
</div>
<Navigation />
</PhoneWrapper>
</TopLevelErrorComponent>
</div>
);
{externalApps.map((App) => (
<Fragment key={App.id}>
<App.Route settings={settings} i18n={i18n} theme={theme}/>
</Fragment>
))}
</>
<NotificationAlert/>
<PhoneSnackbar/>
</div>
<Navigation/>
</PhoneWrapper>
</TopLevelErrorComponent>
</div>
);
};

InjectDebugData<any>([
{
app: 'PHONE',
method: PhoneEvents.SET_CONFIG,
data: DefaultConfig,
},
{
app: 'PHONE',
method: PhoneEvents.SET_VISIBILITY,
data: true,
},
{
app: 'PHONE',
method: PhoneEvents.SET_CONFIG,
data: DefaultConfig,
},
{
app: 'PHONE',
method: PhoneEvents.SET_VISIBILITY,
data: true,
},
]);

InjectDebugData<SystemNotificationDTO>([
{
app: 'SYSTEM',
method: NotificationEvents.CREATE_SYSTEM_NOTIFICATION,
data: {
content: "This is a test notification",
controls: true,
duration: 5000,
keepOpen: true,
onCancel: () => console.log("Cancelled"),
onConfirm: () => console.log("Confirmed"),
uniqId: "test",
secondaryTitle: "Test Notification",
}
}
])

export default Phone;
3 changes: 2 additions & 1 deletion apps/phone/src/apps/dialer/components/DialerApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import DialerNavBar from './DialerNavBar';
import { ContactList } from '../../contacts/components/List/ContactList';
import { DialerThemeProvider } from '../providers/DialerThemeProvider';
import { LoadingSpinner } from '@ui/components/LoadingSpinner';
import InjectDebugData from "@os/debug/InjectDebugData";

export const DialerApp: React.FC = () => {
return (
Expand All @@ -32,4 +33,4 @@ export const DialerApp: React.FC = () => {
</AppWrapper>
</DialerThemeProvider>
);
};
};
2 changes: 1 addition & 1 deletion apps/phone/src/apps/twitter/components/TwitterApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ InjectDebugData<any>(
retweetIdentifier: '',
avatar_url: '',
id: 116,
message: 'Go is better!',
message: 'Go is better! Here is why: Go is a statically typed, compiled language in the tradition of C, with memory safety, garbage collection, structural typing, and CSP-style concurrency. The compiler, tools, and source code are all free and open source.',
createdAt: '2021-12-01 00:42:03',
updatedAt: '2021-12-01 00:42:03',
identifier: '',
Expand Down
7 changes: 6 additions & 1 deletion apps/phone/src/lib/RecoilDebugObserver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import React, { useEffect } from 'react';
import { useRecoilSnapshot } from 'recoil';
import defaultConfig from './../config/default.json';

export const RecoilDebugObserver: React.FC = ({ children }) => {

interface RecoilDebugObserverProps {
children: React.ReactNode;
}

export const RecoilDebugObserver: React.FC<RecoilDebugObserverProps> = ({ children }) => {
const snapshot = useRecoilSnapshot();

useEffect(() => {
Expand Down
6 changes: 5 additions & 1 deletion apps/phone/src/lib/RecoilRootManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import RecoilCacheReset from './RecoilCacheReset';
// a refresh
// This is liable to memory leaky behavior in extreme cases.

export const RecoilRootManager: React.FC = ({ children }) => {
interface RecoilRootManagerProps {
children: React.ReactNode;
}

export const RecoilRootManager: React.FC<RecoilRootManagerProps> = ({ children }) => {
const [charState, setCharState] = useState(0);

useNuiEvent('PHONE', PhoneEvents.UNLOAD_CHARACTER, () => {
Expand Down
6 changes: 5 additions & 1 deletion apps/phone/src/os/call/components/CallNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ const StyledControls = styled(Box)(({ theme }) => ({
right: '0',
}));

export const CallNotification: React.FC = ({ children }) => (
interface CallNotificationProps {
children: React.ReactNode;
}

export const CallNotification: React.FC<CallNotificationProps> = ({ children }) => (
<Box paddingBottom="48px">
<Box>{children}</Box>
<StyledControls>
Expand Down
4 changes: 2 additions & 2 deletions apps/phone/src/os/call/hooks/useCallNotifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { ActiveCall } from '@typings/call';
import { useApp } from '@os/apps/hooks/useApps';
import { useNotifications } from '@os/notifications/hooks/useNotifications';
import { CallNotification } from '../components/CallNotification';
import { useContactActions } from '../../../apps/contacts/hooks/useContactActions';
import { useContacts } from '../../../apps/contacts/hooks/state';
import { useContactActions } from '@apps/contacts/hooks/useContactActions';
import { useContacts } from '@apps/contacts/hooks/state';

const NOTIFICATION_ID = 'call:current';

Expand Down
Loading

0 comments on commit db6e3ab

Please sign in to comment.