From 0ff5f1b79b89ecd4a3068417268c1ad317452c89 Mon Sep 17 00:00:00 2001 From: arc-alex Date: Wed, 28 May 2025 16:58:41 +0200 Subject: [PATCH] deffiretiate main and custom edits --- apps/client/src/common/api/session.ts | 11 ++++++- apps/client/src/common/utils/urlPresets.ts | 30 +++++++++++++++---- apps/client/src/declarations/declaration.d.ts | 3 +- .../panel/network-panel/GenerateLinkForm.tsx | 27 +++++++++++++++-- .../cuesheet/cuesheet-table/CuesheetTable.tsx | 6 ++-- .../cuesheet-table-elements/cuesheetCols.tsx | 12 ++++---- .../api-data/session/session.controller.ts | 2 ++ .../src/api-data/session/session.service.ts | 8 +++++ .../api-data/session/session.validation.ts | 2 ++ 9 files changed, 83 insertions(+), 18 deletions(-) diff --git a/apps/client/src/common/api/session.ts b/apps/client/src/common/api/session.ts index 2449cf18e..6437b4b6d 100644 --- a/apps/client/src/common/api/session.ts +++ b/apps/client/src/common/api/session.ts @@ -20,8 +20,17 @@ export async function generateUrl( baseUrl: string, path: string, lock: boolean, + lockMainFields: boolean, + lockCustomFields: boolean, authenticate: boolean, ): Promise { - const res = await axios.post(`${sessionPath}/url`, { baseUrl, path, lock, authenticate }); + const res = await axios.post(`${sessionPath}/url`, { + baseUrl, + path, + lock, + lockMainFields, + lockCustomFields, + authenticate, + }); return res.data.url; } diff --git a/apps/client/src/common/utils/urlPresets.ts b/apps/client/src/common/utils/urlPresets.ts index 19795af2d..78fee6e8d 100644 --- a/apps/client/src/common/utils/urlPresets.ts +++ b/apps/client/src/common/utils/urlPresets.ts @@ -45,11 +45,14 @@ export function getRouteFromPreset(location: Path, urlPresets: URLPreset[]): str const locked = searchParams.get('locked'); const token = searchParams.get('token'); + const lmain = searchParams.get('lmain'); + const lcustom = searchParams.get('lcustom'); + // we need to check if the whole url is an alias const foundPreset = urlPresets.find((preset) => preset.alias === removeTrailingSlash(currentURL) && preset.enabled); if (foundPreset) { // if so, we can redirect to the preset path - return generatePathFromPreset(foundPreset.pathAndParams, foundPreset.alias, locked, token); + return generatePathFromPreset(foundPreset.pathAndParams, foundPreset.alias, locked, token, lmain, lcustom); } // if the current url is not an alias, we check if the alias is in the search parameters @@ -63,7 +66,7 @@ export function getRouteFromPreset(location: Path, urlPresets: URLPreset[]): str for (const preset of urlPresets) { // if the page has a known enabled alias, we check if we need to redirect if (preset.alias === presetOnPage && preset.enabled) { - const newPath = generatePathFromPreset(preset.pathAndParams, preset.alias, locked, token); + const newPath = generatePathFromPreset(preset.pathAndParams, preset.alias, locked, token, lmain, lcustom); if (!arePathsEquivalent(currentPath, newPath)) { // if current path is out of date // return new path so we can redirect @@ -77,7 +80,14 @@ export function getRouteFromPreset(location: Path, urlPresets: URLPreset[]): str /** * Handles generating a path and search parameters from a preset */ -export function generatePathFromPreset(pathAndParams: string, alias: string, locked: string | null, token: string | null ): string { +export function generatePathFromPreset( + pathAndParams: string, + alias: string, + locked: string | null, + token: string | null, + lmain: string | null, + lcustom: string | null, +): string { const path = resolvePath(pathAndParams); const searchParams = new URLSearchParams(path.search); @@ -93,6 +103,14 @@ export function generatePathFromPreset(pathAndParams: string, alias: string, loc searchParams.set('token', token); } + if (lmain) { + searchParams.set('lmain', lmain); + } + + if (lcustom) { + searchParams.set('lcustom', lcustom); + } + // return path concatenated without the leading slash return `${path.pathname}?${searchParams}`.substring(1); } @@ -106,16 +124,16 @@ export function generatePathFromPreset(pathAndParams: string, alias: string, loc export function arePathsEquivalent(currentPath: string, newPath: string): boolean { const currentUrl = new URL(currentPath, document.location.origin); const newUrl = new URL(newPath, document.location.origin); - + // check path if (currentUrl.pathname !== newUrl.pathname) { - return false + return false; } // check search params // if the params match, we dont need further checks if (currentUrl.searchParams.toString() === newUrl.searchParams.toString()) { - return true + return true; } // if there is no match, we check the edge cases for the url sharing feature diff --git a/apps/client/src/declarations/declaration.d.ts b/apps/client/src/declarations/declaration.d.ts index ffc1afc68..90910ae84 100644 --- a/apps/client/src/declarations/declaration.d.ts +++ b/apps/client/src/declarations/declaration.d.ts @@ -31,7 +31,8 @@ declare module '@tanstack/react-table' { options: { showDelayedTimes: boolean; hideTableSeconds: boolean; - allowEdits: boolean; + allowMainEdits: boolean; + allowCustomEdits: boolean; }; } } diff --git a/apps/client/src/features/app-settings/panel/network-panel/GenerateLinkForm.tsx b/apps/client/src/features/app-settings/panel/network-panel/GenerateLinkForm.tsx index 8773bd885..768b71a35 100644 --- a/apps/client/src/features/app-settings/panel/network-panel/GenerateLinkForm.tsx +++ b/apps/client/src/features/app-settings/panel/network-panel/GenerateLinkForm.tsx @@ -20,6 +20,8 @@ interface GenerateLinkFormOptions { baseUrl: string; path: string; lock: boolean; + lockMainFields: boolean; + lockCustomFields: boolean; authenticate: boolean; } @@ -35,13 +37,15 @@ export default function GenerateLinkForm() { handleSubmit, register, setError, - formState: { errors }, + formState: { errors, dirtyFields }, } = useForm({ mode: 'onChange', defaultValues: { baseUrl: currentHostName, path: '', lock: false, + lockMainFields: false, + lockCustomFields: false, authenticate: false, }, resetOptions: { @@ -53,7 +57,14 @@ export default function GenerateLinkForm() { try { setFormState('loading'); const baseUrl = linkToOtherHost(options.baseUrl); - const url = await generateUrl(baseUrl, options.path, options.lock, options.authenticate); + const url = await generateUrl( + baseUrl, + options.path, + options.lock, + options.lockMainFields, + options.lockCustomFields, + options.authenticate, + ); await copyToClipboard(url); setUrl(url); setFormState('success'); @@ -119,6 +130,18 @@ export default function GenerateLinkForm() { /> + {dirtyFields.lock && ( + <> + + + + + + + + + + )} diff --git a/apps/client/src/views/cuesheet/cuesheet-table/CuesheetTable.tsx b/apps/client/src/views/cuesheet/cuesheet-table/CuesheetTable.tsx index c3156bfba..9d3834bd6 100644 --- a/apps/client/src/views/cuesheet/cuesheet-table/CuesheetTable.tsx +++ b/apps/client/src/views/cuesheet/cuesheet-table/CuesheetTable.tsx @@ -27,7 +27,8 @@ export default function CuesheetTable(props: CuesheetTableProps) { const { updateEvent, updateTimer } = useEventAction(); const [searchParams] = useSearchParams(); - const blockEdits = searchParams.get('locked') ?? false; + const allowMainEdits = !searchParams.get('lmain'); + const allowCustomEdits = !searchParams.get('lcustom'); const { followSelected, showDelayedTimes, hideTableSeconds } = useCuesheetOptions(); const { columnVisibility, columnOrder, columnSizing, resetColumnOrder, setColumnVisibility, setColumnSizing } = @@ -81,7 +82,8 @@ export default function CuesheetTable(props: CuesheetTableProps) { options: { showDelayedTimes, hideTableSeconds, - allowEdits: !blockEdits, + allowMainEdits, + allowCustomEdits, }, }, }); diff --git a/apps/client/src/views/cuesheet/cuesheet-table/cuesheet-table-elements/cuesheetCols.tsx b/apps/client/src/views/cuesheet/cuesheet-table/cuesheet-table-elements/cuesheetCols.tsx index a5dea8365..d3a829822 100644 --- a/apps/client/src/views/cuesheet/cuesheet-table/cuesheet-table-elements/cuesheetCols.tsx +++ b/apps/client/src/views/cuesheet/cuesheet-table/cuesheet-table-elements/cuesheetCols.tsx @@ -37,7 +37,7 @@ function MakeStart({ getValue, row, table }: CellContext {formattedTime} @@ -71,7 +71,7 @@ function MakeEnd({ getValue, row, table }: CellContext {formattedTime} @@ -97,7 +97,7 @@ function MakeDuration({ getValue, row, table }: CellContext {formattedDuration} @@ -124,7 +124,7 @@ function MakeMultiLineField({ row, column, table }: CellContext ); } @@ -167,7 +167,7 @@ function MakeSingleLineField({ row, column, table }: CellContext ); } @@ -191,7 +191,7 @@ function MakeCustomField({ row, column, table }: CellContext ); } diff --git a/apps/server/src/api-data/session/session.controller.ts b/apps/server/src/api-data/session/session.controller.ts index 8d2ba9957..7d3d3f233 100644 --- a/apps/server/src/api-data/session/session.controller.ts +++ b/apps/server/src/api-data/session/session.controller.ts @@ -31,6 +31,8 @@ export async function generateUrl(req: Request, res: Response {