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

V2 fix offline #294

Merged
merged 2 commits into from
Feb 23, 2023
Merged
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
10 changes: 3 additions & 7 deletions apps/client/src/common/hooks-query/useAliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ import { ALIASES } from '../api/apiConstants';
import { getAliases } from '../api/ontimeApi';

export default function useAliases() {
const {
data,
status,
isError,
refetch,
} = useQuery({
const { data, status, isError, refetch } = useQuery({
queryKey: ALIASES,
queryFn: getAliases,
placeholderData: [],
retry: 5,
retryDelay: attempt => attempt * 2500,
retryDelay: (attempt) => attempt * 2500,
refetchInterval: queryRefetchIntervalSlow,
networkMode: 'always',
});

return { data, status, isError, refetch };
Expand Down
10 changes: 3 additions & 7 deletions apps/client/src/common/hooks-query/useEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ import { fetchEvent } from '../api/eventApi';
import { eventDataPlaceholder } from '../models/EventData.type';

export default function useEvent() {
const {
data,
status,
isError,
refetch,
} = useQuery({
const { data, status, isError, refetch } = useQuery({
queryKey: EVENT_TABLE,
queryFn: fetchEvent,
placeholderData: eventDataPlaceholder,
retry: 5,
retryDelay: attempt => attempt * 2500,
retryDelay: (attempt) => attempt * 2500,
refetchInterval: queryRefetchIntervalSlow,
networkMode: 'always',
});

return { data, status, isError, refetch };
Expand Down
10 changes: 3 additions & 7 deletions apps/client/src/common/hooks-query/useInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ import { getInfo } from '../api/ontimeApi';
import { ontimePlaceholderInfo } from '../models/Info.types';

export default function useInfo() {
const {
data,
status,
isError,
refetch,
} = useQuery({
const { data, status, isError, refetch } = useQuery({
queryKey: APP_INFO,
queryFn: getInfo,
placeholderData: ontimePlaceholderInfo,
retry: 5,
retryDelay: attempt => attempt * 2500,
retryDelay: (attempt) => attempt * 2500,
refetchInterval: queryRefetchIntervalSlow,
networkMode: 'always',
});

return { data, status, isError, refetch };
Expand Down
10 changes: 3 additions & 7 deletions apps/client/src/common/hooks-query/useOscSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ import { getOSC } from '../api/ontimeApi';
import { oscPlaceholderSettings } from '../models/OscSettings.type';

export default function useOscSettings() {
const {
data,
status,
isError,
refetch,
} = useQuery({
const { data, status, isError, refetch } = useQuery({
queryKey: OSC_SETTINGS,
queryFn: getOSC,
placeholderData: oscPlaceholderSettings,
retry: 5,
retryDelay: attempt => attempt * 2500,
retryDelay: (attempt) => attempt * 2500,
refetchInterval: queryRefetchIntervalSlow,
networkMode: 'always',
});

return { data, status, isError, refetch };
Expand Down
10 changes: 3 additions & 7 deletions apps/client/src/common/hooks-query/useRundown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ import { RUNDOWN_TABLE } from '../api/apiConstants';
import { fetchRundown } from '../api/eventsApi';

export default function useRundown() {
const {
data,
status,
isError,
refetch,
} = useQuery({
const { data, status, isError, refetch } = useQuery({
queryKey: RUNDOWN_TABLE,
queryFn: fetchRundown,
placeholderData: [],
retry: 5,
retryDelay: attempt => attempt * 2500,
retryDelay: (attempt) => attempt * 2500,
refetchInterval: queryRefetchInterval,
networkMode: 'always',
});

return { data, status, isError, refetch };
Expand Down
10 changes: 3 additions & 7 deletions apps/client/src/common/hooks-query/useSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ import { getSettings } from '../api/ontimeApi';
import { ontimePlaceholderSettings } from '../models/OntimeSettings.type';

export default function useSettings() {
const {
data,
status,
isError,
refetch,
} = useQuery({
const { data, status, isError, refetch } = useQuery({
queryKey: APP_SETTINGS,
queryFn: getSettings,
placeholderData: ontimePlaceholderSettings,
retry: 5,
retryDelay: attempt => attempt * 2500,
retryDelay: (attempt) => attempt * 2500,
refetchInterval: queryRefetchIntervalSlow,
networkMode: 'always',
});

return { data, status, isError, refetch };
Expand Down
10 changes: 3 additions & 7 deletions apps/client/src/common/hooks-query/useUserFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ import { getUserFields } from '../api/ontimeApi';
import { userFieldsPlaceholder } from '../models/UserFields.type';

export default function useUserFields() {
const {
data,
status,
isError,
refetch,
} = useQuery({
const { data, status, isError, refetch } = useQuery({
queryKey: USERFIELDS,
queryFn: getUserFields,
placeholderData: userFieldsPlaceholder,
retry: 5,
retryDelay: attempt => attempt * 2500,
retryDelay: (attempt) => attempt * 2500,
refetchInterval: queryRefetchInterval,
networkMode: 'always',
});

return { data, status, isError, refetch };
Expand Down
10 changes: 3 additions & 7 deletions apps/client/src/common/hooks-query/useViewSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ import { getView } from '../api/ontimeApi';
import { viewsSettingsPlaceholder } from '../models/ViewSettings.type';

export default function useViewSettings() {
const {
data,
status,
isError,
refetch,
} = useQuery({
const { data, status, isError, refetch } = useQuery({
queryKey: VIEW_SETTINGS,
queryFn: getView,
placeholderData: viewsSettingsPlaceholder,
retry: 5,
retryDelay: attempt => attempt * 2500,
retryDelay: (attempt) => attempt * 2500,
refetchInterval: queryRefetchIntervalSlow,
networkMode: 'always',
});

return { data, status, isError, refetch };
Expand Down
24 changes: 14 additions & 10 deletions apps/client/src/common/hooks/useEventAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ export const useEventAction = () => {
onSettled: () => {
queryClient.invalidateQueries(RUNDOWN_TABLE);
},
networkMode: 'always',
});

type AddOptions = {
defaultPublic?: boolean;
startTimeIsLastEnd?: boolean;
lastEventId?: string;
after?: string;
}
};

/**
* Adds an event to rundown
Expand All @@ -52,7 +53,6 @@ export const useEventAction = () => {
async (event: Partial<OntimeRundownEntry>, options?: AddOptions) => {
const newEvent: Partial<OntimeRundownEntry> = { ...event };


// ************* CHECK OPTIONS
// there is an option to pass an index of an array to use as start time
// only events have options
Expand Down Expand Up @@ -91,7 +91,7 @@ export const useEventAction = () => {
// @ts-expect-error we know that the event here is one of the defined types
await _addEventMutation.mutateAsync(newEvent);
} catch (error) {
if(!axios.isAxiosError(error)){
if (!axios.isAxiosError(error)) {
emitError(`Error fetching data: ${(error as AxiosError).message}`);
} else {
emitError(`Error fetching data: ${error}`);
Expand Down Expand Up @@ -130,6 +130,7 @@ export const useEventAction = () => {
onSettled: async () => {
await queryClient.invalidateQueries([RUNDOWN_TABLE_KEY]);
},
networkMode: 'always',
});

/**
Expand All @@ -140,12 +141,11 @@ export const useEventAction = () => {
try {
await _updateEventMutation.mutateAsync(event);
} catch (error) {
if(!axios.isAxiosError(error)){
if (!axios.isAxiosError(error)) {
emitError(`Error updating event: ${(error as AxiosError).message}`);
} else {
emitError(`Error updating event: ${error}`);
}

}
},
[_updateEventMutation, emitError],
Expand Down Expand Up @@ -182,6 +182,7 @@ export const useEventAction = () => {
onSettled: () => {
queryClient.invalidateQueries(RUNDOWN_TABLE);
},
networkMode: 'always',
});

/**
Expand All @@ -191,8 +192,8 @@ export const useEventAction = () => {
async (eventId: string) => {
try {
await _deleteEventMutation.mutateAsync(eventId);
} catch (error) {
if(!axios.isAxiosError(error)){
} catch (error) {
if (!axios.isAxiosError(error)) {
emitError(`Error deleting event: ${(error as AxiosError).message}`);
} else {
emitError(`Error deleting event: ${error}`);
Expand Down Expand Up @@ -231,6 +232,7 @@ export const useEventAction = () => {
onSettled: () => {
queryClient.invalidateQueries(RUNDOWN_TABLE);
},
networkMode: 'always',
});

/**
Expand All @@ -240,7 +242,7 @@ export const useEventAction = () => {
try {
await _deleteAllEventsMutation.mutateAsync();
} catch (error) {
if(!axios.isAxiosError(error)){
if (!axios.isAxiosError(error)) {
emitError(`Error deleting events: ${(error as AxiosError).message}`);
} else {
emitError(`Error deleting events: ${error}`);
Expand All @@ -257,6 +259,7 @@ export const useEventAction = () => {
onSettled: () => {
queryClient.invalidateQueries(RUNDOWN_TABLE);
},
networkMode: 'always',
});

/**
Expand All @@ -267,7 +270,7 @@ export const useEventAction = () => {
try {
await _applyDelayMutation.mutateAsync(delayEventId);
} catch (error) {
if(!axios.isAxiosError(error)){
if (!axios.isAxiosError(error)) {
emitError(`Error applying delay: ${(error as AxiosError).message}`);
} else {
emitError(`Error applying delay: ${error}`);
Expand Down Expand Up @@ -310,6 +313,7 @@ export const useEventAction = () => {
onSettled: () => {
queryClient.invalidateQueries(RUNDOWN_TABLE);
},
networkMode: 'always',
});

/**
Expand All @@ -325,7 +329,7 @@ export const useEventAction = () => {
};
await _reorderEventMutation.mutateAsync(reorderObject);
} catch (error) {
if(!axios.isAxiosError(error)){
if (!axios.isAxiosError(error)) {
emitError(`Error re-ordering event: ${(error as AxiosError).message}`);
} else {
emitError(`Error re-ordering event: ${error}`);
Expand Down
9 changes: 6 additions & 3 deletions apps/server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { join, resolve } from 'path';

import { initiateOSC, shutdownOSCServer } from './controllers/OscController.js';
import { initSentry } from './modules/sentry.js';
import { currentDirectory, environment, isProduction, resolvedPath, uiPath } from './setup.js';
import { currentDirectory, environment, isProduction, resolvedPath } from './setup.js';
import { ONTIME_VERSION } from './ONTIME_VERSION.js';
import { OSCSettings } from 'ontime-types';

Expand Down Expand Up @@ -62,10 +62,13 @@ app.use('/playback', playbackRouter);
app.use('/external', express.static(join(currentDirectory, 'external')));

// serve static - react, in test mode we fetch the React app from module
app.use(express.static(join(currentDirectory, resolvedPath(), uiPath)));
const newpath = join(currentDirectory, resolvedPath());
console.log('serving content at ', newpath);

app.use(express.static(join(currentDirectory, resolvedPath())));

app.get('*', (req, res) => {
res.sendFile(resolve(currentDirectory, resolvedPath(), uiPath, 'index.html'));
res.sendFile(resolve(currentDirectory, resolvedPath(), 'index.html'));
});

// Implement catch all
Expand Down
5 changes: 2 additions & 3 deletions apps/server/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ export const isProduction = env === 'production' && !isTest;

// =================================================
// resolve path to external
const productionPath = '../../Resources/extraResources/';
const devPath = '../../';
const productionPath = '../../Resources/extraResources/client';
const devPath = '../../client/build/';

export const uiPath = 'client/';
export const resolvedPath = (): string => (isProduction ? productionPath : devPath);

// resolve file URL in both CJS and ESM (build and dev)
Expand Down