Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offline indicator #877

Draft
wants to merge 5 commits into
base: v3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/client/src/common/stores/appModeStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@ type AppModeStore = {
setMode: (mode: AppMode) => void;
cursor: string | null;
setCursor: (cursor: string | null) => void;
connected: boolean;
setConnected: (c: boolean) => void;
};

export const useAppMode = create<AppModeStore>()((set) => ({
mode: getModeFromSession(),
cursor: null,
setMode: (mode: AppMode) => {
persistModeToSession(mode);

return set(() => {
return { mode };
});
},
setCursor: (cursor: string | null) => set(() => ({ cursor })),
connected: false,
setConnected: (connected: boolean) => set(() => ({ connected })),
}));
4 changes: 4 additions & 0 deletions apps/client/src/common/utils/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Log, RuntimeStore } from 'ontime-types';

import { isProduction, RUNTIME, websocketUrl } from '../api/constants';
import { ontimeQueryClient } from '../queryClient';
import { useAppMode } from '../stores/appModeStore';
import { socketClientName } from '../stores/connectionName';
import { addLog } from '../stores/logger';
import { patchRuntime, runtimeStore } from '../stores/runtime';
Expand All @@ -20,6 +21,7 @@ export const connectSocket = (preferredClientName?: string) => {
clearTimeout(reconnectTimeout as NodeJS.Timeout);
hasConnected = true;
reconnectAttempts = 0;
useAppMode.setState({ connected: true });

if (preferredClientName) {
socketSendJson('set-client-name', preferredClientName);
Expand All @@ -28,6 +30,8 @@ export const connectSocket = (preferredClientName?: string) => {

websocket.onclose = () => {
console.warn('WebSocket disconnected');
useAppMode.setState({ connected: false });

if (shouldReconnect) {
reconnectTimeout = setTimeout(() => {
console.warn('WebSocket: attempting reconnect');
Expand Down
18 changes: 17 additions & 1 deletion apps/client/src/features/overview/Overview.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { memo, useMemo } from 'react';
import { Alert, AlertIcon, Tooltip } from '@chakra-ui/react';
import { millisToString } from 'ontime-utils';

import ErrorBoundary from '../../common/components/error-boundary/ErrorBoundary';
import { useRuntimeOverview, useRuntimePlaybackOverview, useTimer } from '../../common/hooks/useSocket';
import useProjectData from '../../common/hooks-query/useProjectData';
import { useAppMode } from '../../common/stores/appModeStore';
import { enDash } from '../../common/utils/styleUtils';

import { TimeColumn, TimeRow } from './composite/TimeLayout';
Expand All @@ -26,6 +28,7 @@ function _EditorOverview({ children }: { children: React.ReactNode }) {
<div className={style.overview}>
<ErrorBoundary>
<div className={style.nav}>{children}</div>
<ConnectedIndicator />
<div className={style.info}>
<TitlesOverview />
<div>
Expand Down Expand Up @@ -95,7 +98,7 @@ function TitlesOverview() {
}

function TimerOverview() {
const {current} = useTimer();
const { current } = useTimer();

const display = millisToString(current);

Expand Down Expand Up @@ -125,3 +128,16 @@ function RuntimeOverview() {
</>
);
}

function ConnectedIndicator() {
const { connected } = useAppMode();
return (
<Alert status='error' variant='ontime-transparent-warn' marginLeft='10' width='10'>
<Tooltip label='Server Disconnected!'>
<span>
<AlertIcon hidden={!connected} className={style.blink} />
</span>
</Tooltip>
</Alert>
);
}
13 changes: 13 additions & 0 deletions apps/client/src/theme/OntimeAlert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,16 @@ export const ontimeAlertOnDark = {
color: '#578AF4', // $blue-500
},
};

export const ontimeRedAlertOnDark = {
container: {
fontSize: 'calc(1rem - 1px)',
backgroundColor: '#0000', // $gray-1300
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backgroundColor value '#0000' seems incorrect as it represents full transparency. Consider using a darker shade appropriate for a dark theme.

-    backgroundColor: '#0000', // $gray-1300
+    backgroundColor: '#1a1a1a', // $gray-1300

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
backgroundColor: '#0000', // $gray-1300
backgroundColor: '#1a1a1a', // $gray-1300

color: '#e2e2e2', // $gray-200
borderRadius: '3px',
},
icon: {
alignSelf: 'start',
color: 'red', // $blue-500
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment for the icon color incorrectly references $blue-500. Update the comment to accurately reflect the color used.

-    color: 'red', // $blue-500
+    color: 'red', // Correct color description

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
color: 'red', // $blue-500
color: 'red', // Correct color description

},
};
3 changes: 2 additions & 1 deletion apps/client/src/theme/theme.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { extendTheme } from '@chakra-ui/react';

import { ontimeAlertOnDark } from './OntimeAlert';
import { ontimeAlertOnDark, ontimeRedAlertOnDark } from './OntimeAlert';
import {
ontimeButtonFilled,
ontimeButtonGhosted,
Expand Down Expand Up @@ -33,6 +33,7 @@ const theme = extendTheme({
Alert: {
variants: {
'ontime-on-dark-info': { ...ontimeAlertOnDark },
'ontime-transparent-warn': { ...ontimeRedAlertOnDark },
},
},
Button: {
Expand Down
Loading