Remove public event feature (#1645)

This commit is contained in:
Alex Christoffer Rasmussen
2025-06-19 18:07:42 +02:00
committed by Carlos Valente
parent 0649678dca
commit 08d9e24871
99 changed files with 173 additions and 1129 deletions
@@ -36,11 +36,10 @@ import { logAxiosError } from '../api/utils';
import { useEditorSettings } from '../stores/editorSettings';
export type EventOptions = Partial<{
// options to any new block (event / delay / block)
// options of any new entries (event / delay / block)
after: MaybeString;
before: MaybeString;
// options to blocks of type OntimeEvent
defaultPublic: boolean;
// options of entries of type OntimeEvent
linkPrevious: boolean;
lastEventId: MaybeString;
}>;
@@ -51,7 +50,6 @@ export type EventOptions = Partial<{
export const useEntryActions = () => {
const queryClient = useQueryClient();
const {
defaultPublic,
linkPrevious,
defaultTimeStrategy,
defaultDuration,
@@ -95,7 +93,6 @@ export const useEntryActions = () => {
const applicationOptions = {
after: options?.after,
before: options?.before,
defaultPublic: options?.defaultPublic ?? defaultPublic,
lastEventId: options?.lastEventId,
linkPrevious: options?.linkPrevious ?? linkPrevious,
};
@@ -111,7 +108,6 @@ export const useEntryActions = () => {
// Override event with options from editor settings
newEntry.linkStart = applicationOptions.linkPrevious;
newEntry.isPublic = applicationOptions.defaultPublic;
if (newEntry.duration === undefined && newEntry.timeEnd === undefined) {
newEntry.duration = parseUserTime(defaultDuration);
@@ -157,7 +153,6 @@ export const useEntryActions = () => {
defaultDangerTime,
defaultDuration,
defaultEndAction,
defaultPublic,
defaultTimerType,
defaultTimeStrategy,
defaultWarnTime,
@@ -1,46 +0,0 @@
import { useEffect, useState } from 'react';
const scriptTagId = 'ontime-override';
export const useRuntimeStylesheet = (pathToFile) => {
const [shouldRender, setShouldRender] = useState(false);
useEffect(() => {
const fetchData = async () => {
const response = await fetch(pathToFile);
if (response.ok) {
return response.text();
}
};
if (!pathToFile) {
document.getElementById(scriptTagId)?.remove();
setShouldRender(true);
return;
}
if (document.getElementById(scriptTagId)) {
setShouldRender(true);
return;
}
setShouldRender(false);
const styleSheet = document.createElement('style');
styleSheet.rel = 'stylesheet';
styleSheet.setAttribute('id', scriptTagId);
fetchData()
.then((data) => {
styleSheet.innerHTML = data;
document.head.append(styleSheet);
})
.catch((error) => {
console.error(`Error loading stylesheet: ${error}`);
})
.finally(() => {
// schedule render for next tick
setTimeout(() => setShouldRender(true), 0);
});
}, [pathToFile]);
return { shouldRender };
};
@@ -0,0 +1,75 @@
import { useEffect, useState } from 'react';
const scriptTagId = 'ontime-override';
export const useRuntimeStylesheet = (pathToFile?: string): { shouldRender: boolean } => {
const [shouldRender, setShouldRender] = useState(false);
/**
* When a view mounts or the stylesheet path changes we need to handle potentially loading a new stylesheet
* - if no path is given, ensure there is no stylesheet loaded
* - if a path is given, fetch the stylesheet and inject it into the document head
* @returns { shouldRender: boolean } - after the stylesheet is handled and the clients are ready to render
*/
useEffect(() => {
if (!pathToFile) {
handleNoStylesheet();
return;
}
// there is already a stylesheet loaded, nothing further to do
if (document.getElementById(scriptTagId)) {
setShouldRender(true);
return;
}
setShouldRender(false);
fetchStylesheetData(pathToFile)
.then((data: string | undefined) => {
if (!data) {
console.error('Error loading stylesheet: no data');
return;
}
return injectStylesheet(data);
})
.catch((error: unknown) => {
console.error(`Error loading stylesheet: ${error}`);
})
.finally(() => {
// schedule render for next tick
setTimeout(() => setShouldRender(true), 0);
});
/**
* No stylesheet was provided, remove any existing stylesheet
*/
function handleNoStylesheet() {
document.getElementById(scriptTagId)?.remove();
setShouldRender(true);
}
/**
* Get data from backend
*/
async function fetchStylesheetData(path: string) {
const response = await fetch(path);
if (response.ok) {
return response.text();
}
return undefined;
}
/**
* Add a stylesheet with given content to the document head
*/
async function injectStylesheet(styleContent: string) {
const styleSheet = document.createElement('style');
styleSheet.setAttribute('id', scriptTagId);
styleSheet.innerHTML = styleContent;
document.head.append(styleSheet);
}
}, [pathToFile]);
return { shouldRender };
};
@@ -3,8 +3,6 @@ import { ProjectData } from 'ontime-types';
export const projectDataPlaceholder: ProjectData = {
title: '',
description: '',
publicUrl: '',
publicInfo: '',
backstageUrl: '',
backstageInfo: '',
projectLogo: null,
@@ -10,7 +10,6 @@ type EditorSettingsStore = {
defaultTimeStrategy: TimeStrategy;
defaultWarnTime: string;
defaultDangerTime: string;
defaultPublic: boolean;
defaultTimerType: TimerType;
defaultEndAction: EndAction;
setDefaultDuration: (defaultDuration: string) => void;
@@ -18,7 +17,6 @@ type EditorSettingsStore = {
setTimeStrategy: (timeStrategy: TimeStrategy) => void;
setWarnTime: (warnTime: string) => void;
setDangerTime: (dangerTime: string) => void;
setDefaultPublic: (defaultPublic: boolean) => void;
setDefaultTimerType: (defaultTimerType: TimerType) => void;
setDefaultEndAction: (defaultEndAction: EndAction) => void;
};
@@ -29,7 +27,6 @@ export const editorSettingsDefaults = {
timeStrategy: TimeStrategy.LockDuration,
warnTime: '00:02:00', // 120000 same as backend
dangerTime: '00:01:00', // 60000 same as backend
isPublic: true,
timerType: TimerType.CountDown,
endAction: EndAction.None,
};
@@ -40,7 +37,6 @@ enum EditorSettingsKeys {
DefaultTimeStrategy = 'ontime-time-strategy',
DefaultWarnTime = 'ontime-default-warn-time',
DefaultDangerTime = 'ontime-default-danger-time',
DefaultPublic = 'ontime-default-public',
DefaultTimerType = 'ontime-default-timer-type',
DefaultEndAction = 'ontime-default-end-action',
}
@@ -55,7 +51,6 @@ export const useEditorSettings = create<EditorSettingsStore>((set) => {
),
defaultWarnTime: localStorage.getItem(EditorSettingsKeys.DefaultWarnTime) ?? editorSettingsDefaults.warnTime,
defaultDangerTime: localStorage.getItem(EditorSettingsKeys.DefaultDangerTime) ?? editorSettingsDefaults.dangerTime,
defaultPublic: booleanFromLocalStorage(EditorSettingsKeys.DefaultPublic, editorSettingsDefaults.isPublic),
defaultTimerType: validateTimerType(
localStorage.getItem(EditorSettingsKeys.DefaultTimerType),
editorSettingsDefaults.timerType,
@@ -92,11 +87,6 @@ export const useEditorSettings = create<EditorSettingsStore>((set) => {
localStorage.setItem(EditorSettingsKeys.DefaultDangerTime, String(defaultDangerTime));
return { defaultDangerTime };
}),
setDefaultPublic: (defaultPublic) =>
set(() => {
localStorage.setItem(EditorSettingsKeys.DefaultPublic, String(defaultPublic));
return { defaultPublic };
}),
setDefaultTimerType: (defaultTimerType) =>
set(() => {
localStorage.setItem(EditorSettingsKeys.DefaultTimerType, String(defaultTimerType));
@@ -19,7 +19,6 @@ describe('cloneEvent()', () => {
linkStart: false,
countToEnd: false,
endAction: EndAction.None,
isPublic: false,
skip: false,
colour: 'F00',
revision: 10,
@@ -52,7 +51,6 @@ describe('cloneEvent()', () => {
countToEnd: original.countToEnd,
linkStart: original.linkStart,
endAction: original.endAction,
isPublic: original.isPublic,
skip: original.skip,
colour: original.colour,
revision: 0,
-1
View File
@@ -20,7 +20,6 @@ export const cloneEvent = (event: OntimeEvent): ClonedEvent => {
countToEnd: event.countToEnd,
linkStart: event.linkStart,
endAction: event.endAction,
isPublic: event.isPublic,
skip: event.skip,
colour: event.colour,
parent: event.parent,