V2 fix offline (#294)

* fix: resolve path to UI build in dev

* fix: configure offline fetching
This commit is contained in:
Carlos Valente
2023-02-23 21:10:41 +01:00
committed by GitHub
parent 70cc071425
commit 03552056cb
11 changed files with 46 additions and 72 deletions
@@ -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 };
@@ -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 };
@@ -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 };
@@ -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 };
@@ -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 };
@@ -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 };
@@ -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 };
@@ -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 };
+14 -10
View File
@@ -36,6 +36,7 @@ export const useEventAction = () => {
onSettled: () => {
queryClient.invalidateQueries(RUNDOWN_TABLE);
},
networkMode: 'always',
});
type AddOptions = {
@@ -43,7 +44,7 @@ export const useEventAction = () => {
startTimeIsLastEnd?: boolean;
lastEventId?: string;
after?: string;
}
};
/**
* Adds an event to rundown
@@ -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
@@ -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}`);
@@ -130,6 +130,7 @@ export const useEventAction = () => {
onSettled: async () => {
await queryClient.invalidateQueries([RUNDOWN_TABLE_KEY]);
},
networkMode: 'always',
});
/**
@@ -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],
@@ -182,6 +182,7 @@ export const useEventAction = () => {
onSettled: () => {
queryClient.invalidateQueries(RUNDOWN_TABLE);
},
networkMode: 'always',
});
/**
@@ -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}`);
@@ -231,6 +232,7 @@ export const useEventAction = () => {
onSettled: () => {
queryClient.invalidateQueries(RUNDOWN_TABLE);
},
networkMode: 'always',
});
/**
@@ -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}`);
@@ -257,6 +259,7 @@ export const useEventAction = () => {
onSettled: () => {
queryClient.invalidateQueries(RUNDOWN_TABLE);
},
networkMode: 'always',
});
/**
@@ -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}`);
@@ -310,6 +313,7 @@ export const useEventAction = () => {
onSettled: () => {
queryClient.invalidateQueries(RUNDOWN_TABLE);
},
networkMode: 'always',
});
/**
@@ -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}`);
+6 -3
View File
@@ -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';
@@ -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
+2 -3
View File
@@ -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)