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 all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { CSSProperties } from 'react';
import { Alert, AlertIcon, Tooltip } from '@chakra-ui/react';

import { useAppMode } from '../../stores/appModeStore';

import moduleStyle from './ConnectedIndicator.module.scss';

export function ConnectedIndicator(props: { style?: CSSProperties }) {
const { connected } = useAppMode();
const { style } = props;
return (
<Alert status='error' variant='ontime-transparent-warn' marginLeft='10' width='10' style={style}>
<Tooltip label='Server Disconnected!'>
<span>
<AlertIcon hidden={!connected} className={moduleStyle.blink} />
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remember remove the ! before merge

</span>
</Tooltip>
</Alert>
);
}
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
5 changes: 4 additions & 1 deletion apps/client/src/features/overview/Overview.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { memo, useMemo } from 'react';
import { millisToString } from 'ontime-utils';

import { ConnectedIndicator } from '../../common/components/connected-indicator/ConnectedIndicator';
import ErrorBoundary from '../../common/components/error-boundary/ErrorBoundary';
import { useRuntimeOverview, useRuntimePlaybackOverview, useTimer } from '../../common/hooks/useSocket';
import useProjectData from '../../common/hooks-query/useProjectData';
Expand All @@ -26,6 +27,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 @@ -64,6 +66,7 @@ function _CuesheetOverview({ children }: { children: React.ReactNode }) {
<div className={style.overview}>
<ErrorBoundary>
<div className={style.nav}>{children}</div>
<ConnectedIndicator />
<div className={style.info}>
<TitlesOverview />
<TimerOverview />
Expand Down Expand Up @@ -95,7 +98,7 @@ function TitlesOverview() {
}

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

const display = millisToString(current);

Expand Down
3 changes: 3 additions & 0 deletions apps/client/src/features/viewers/backstage/Backstage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CustomFields, Message, OntimeEvent, ProjectData, Settings, SupportedEve
import { millisToString, removeLeadingZero } from 'ontime-utils';

import { overrideStylesURL } from '../../../common/api/constants';
import { ConnectedIndicator } from '../../../common/components/connected-indicator/ConnectedIndicator';
import ProgressBar from '../../../common/components/progress-bar/ProgressBar';
import Schedule from '../../../common/components/schedule/Schedule';
import { ScheduleProvider } from '../../../common/components/schedule/ScheduleContext';
Expand Down Expand Up @@ -99,6 +100,8 @@ export default function Backstage(props: BackstageProps) {

return (
<div className={`backstage ${isMirrored ? 'mirror' : ''}`} data-testid='backstage-view'>
<ConnectedIndicator style={{ position: 'absolute', left: '1em', top: '0.5em' }} />

<ViewParamsEditor paramFields={backstageOptions} />
<div className='project-header'>
{general.title}
Expand Down
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