From c9ad724383b0594a739ecfc273a795f8067f60ba Mon Sep 17 00:00:00 2001 From: koen1711 Date: Sun, 22 Sep 2024 19:16:14 +0200 Subject: [PATCH 1/3] fix: remove useless id field --- src/lib/components/core/popups/popups/SerialMonitor.svelte | 2 +- src/lib/state/workspace.svelte.ts | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib/components/core/popups/popups/SerialMonitor.svelte b/src/lib/components/core/popups/popups/SerialMonitor.svelte index ada5267..a5b6703 100644 --- a/src/lib/components/core/popups/popups/SerialMonitor.svelte +++ b/src/lib/components/core/popups/popups/SerialMonitor.svelte @@ -103,7 +103,7 @@ function insertDate() { {/if} {#if mode === Mode.TEXT}
- {#each $log as item (item.id)} + {#each $log as item}
{formatDate(item.date)}
{item.content}
diff --git a/src/lib/state/workspace.svelte.ts b/src/lib/state/workspace.svelte.ts index 4d4dfa5..10524d3 100644 --- a/src/lib/state/workspace.svelte.ts +++ b/src/lib/state/workspace.svelte.ts @@ -33,7 +33,6 @@ export enum Prompt { export class ConnectionFailedError {} interface LogItem { - id: string; date: Date; content: string; } @@ -96,7 +95,6 @@ function createLogState() { [ ...log, ...items.map((content) => ({ - id: crypto.randomUUID(), date: new Date(), content, })), From d7f392ce7924442678865867208da7941eec242b Mon Sep 17 00:00:00 2001 From: koen1711 Date: Sun, 22 Sep 2024 19:27:41 +0200 Subject: [PATCH 2/3] fix: remove all uses of crypto.randomUUID with a better counter system --- src/lib/state/popup.svelte.ts | 4 +++- src/lib/state/workspace.svelte.ts | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/state/popup.svelte.ts b/src/lib/state/popup.svelte.ts index bb5b86d..e854fd2 100644 --- a/src/lib/state/popup.svelte.ts +++ b/src/lib/state/popup.svelte.ts @@ -25,6 +25,7 @@ export interface PopupState { function createPopups() { const { subscribe, update, set } = writable([]); + let count = 0; return { subscribe, @@ -32,13 +33,14 @@ function createPopups() { let onclose: (value: any) => void; const promise = new Promise((resolve) => (onclose = resolve)); const state: PopupState = { - id: crypto.randomUUID(), + id: `${count++}`, position: { x: 0, y: 0 }, popup, onclose, anchor: Anchor.Center, ...initialState, }; + if (count > 1000) count = 0; update((popups) => { if ( popups.find( diff --git a/src/lib/state/workspace.svelte.ts b/src/lib/state/workspace.svelte.ts index 10524d3..9f209a1 100644 --- a/src/lib/state/workspace.svelte.ts +++ b/src/lib/state/workspace.svelte.ts @@ -33,6 +33,7 @@ export enum Prompt { export class ConnectionFailedError {} interface LogItem { + id: string; date: Date; content: string; } @@ -67,6 +68,7 @@ let writer: WritableStreamDefaultWriter; function createLogState() { const { subscribe, update, set } = writable([]); let buffer = ""; + let count = 0; return { subscribe, @@ -95,11 +97,13 @@ function createLogState() { [ ...log, ...items.map((content) => ({ + id: `${count}`, date: new Date(), content, })), ].slice(-100), ); + if (count > 100) count = 0; } }, }; From 755f23e7a00b7c15bb43b351d45285245c27e397 Mon Sep 17 00:00:00 2001 From: koen1711 Date: Sun, 22 Sep 2024 19:40:33 +0200 Subject: [PATCH 3/3] chore: fix all issues --- src/lib/components/core/popups/popups/SerialMonitor.svelte | 2 +- src/lib/state/popup.svelte.ts | 3 ++- src/lib/state/workspace.svelte.ts | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/components/core/popups/popups/SerialMonitor.svelte b/src/lib/components/core/popups/popups/SerialMonitor.svelte index a5b6703..ada5267 100644 --- a/src/lib/components/core/popups/popups/SerialMonitor.svelte +++ b/src/lib/components/core/popups/popups/SerialMonitor.svelte @@ -103,7 +103,7 @@ function insertDate() { {/if} {#if mode === Mode.TEXT}
- {#each $log as item} + {#each $log as item (item.id)}
{formatDate(item.date)}
{item.content}
diff --git a/src/lib/state/popup.svelte.ts b/src/lib/state/popup.svelte.ts index e854fd2..e025bdd 100644 --- a/src/lib/state/popup.svelte.ts +++ b/src/lib/state/popup.svelte.ts @@ -33,13 +33,14 @@ function createPopups() { let onclose: (value: any) => void; const promise = new Promise((resolve) => (onclose = resolve)); const state: PopupState = { - id: `${count++}`, + id: `${count}`, position: { x: 0, y: 0 }, popup, onclose, anchor: Anchor.Center, ...initialState, }; + count++; if (count > 1000) count = 0; update((popups) => { if ( diff --git a/src/lib/state/workspace.svelte.ts b/src/lib/state/workspace.svelte.ts index 9f209a1..3ff52ff 100644 --- a/src/lib/state/workspace.svelte.ts +++ b/src/lib/state/workspace.svelte.ts @@ -103,6 +103,7 @@ function createLogState() { })), ].slice(-100), ); + count++; if (count > 100) count = 0; } },