From 59998eb267951005d1d459f610cc650c39256022 Mon Sep 17 00:00:00 2001 From: OrigamingWasTaken Date: Sat, 2 Nov 2024 22:01:00 +0100 Subject: [PATCH] Fix "Import" button in Flags editor --- .../components/flag-editor/flag-table.svelte | 67 ++-- frontend/src/windows/main/pages/Info.svelte | 2 +- frontend/src/windows/main/ts/utils/index.ts | 57 ---- frontend/src/windows/main/ts/utils/json.ts | 306 ++++++++++++++++++ package.json | 2 +- 5 files changed, 355 insertions(+), 79 deletions(-) create mode 100644 frontend/src/windows/main/ts/utils/json.ts diff --git a/frontend/src/windows/main/components/flag-editor/flag-table.svelte b/frontend/src/windows/main/components/flag-editor/flag-table.svelte index 4dc3664..342c24b 100644 --- a/frontend/src/windows/main/components/flag-editor/flag-table.svelte +++ b/frontend/src/windows/main/components/flag-editor/flag-table.svelte @@ -4,17 +4,18 @@ import * as Card from '$lib/components/ui/card'; import { Checkbox } from '$lib/components/ui/checkbox'; import * as Dialog from '$lib/components/ui/dialog/index.js'; + import * as DropdownMenu from '$lib/components/ui/dropdown-menu'; import { Input } from '$lib/components/ui/input'; import { Label } from '$lib/components/ui/label'; import { Switch } from '$lib/components/ui/switch'; import * as Table from '$lib/components/ui/table'; import { clipboard } from '@neutralinojs/lib'; import beautify from 'json-beautify'; - import { Braces, Clipboard, Delete, Plus, Search, Ellipsis, Edit, Trash2, Copy } from 'lucide-svelte'; + import { Braces, Clipboard, Delete, Ellipsis, Plus, Search } from 'lucide-svelte'; import { createEventDispatcher } from 'svelte'; import { toast } from 'svelte-sonner'; - import { correctAndParseJSON } from '../../ts/utils/'; - import * as DropdownMenu from '$lib/components/ui/dropdown-menu'; + import { correctAndParseJSON } from '../../ts/utils/json'; + import Textarea from '$lib/components/ui/textarea/textarea.svelte'; type FastFlag = string | boolean | null | number; interface EditorFlag { @@ -103,24 +104,15 @@ let willBeReplacedFlags: string[] = []; let newEditorFlags: EditorFlag[] = []; - async function importFlags(): Promise { - let clipboardContent: string = ''; - try { - clipboardContent = await clipboard.readText(); - } catch (err) { - toast.error("Couldn't read clipboard"); - console.error("Couldn't read clipboard:", err); - return; - } + let openImportFlagsDialog = false; + let importFlagsDialogValue: string; + function showImportFlagsDialog() { + openImportFlagsDialog = true; + } + async function importFlags(flagsString: string): Promise { let flagsJson: Record = {}; - try { - flagsJson = correctAndParseJSON(clipboardContent).parsedJSON; - } catch (err) { - console.error(err) - toast.error("Couldn't import flags, your JSON is probably invalid (malformatted)"); - return; - } + flagsJson = correctAndParseJSON(flagsString, { friendly: true }); // Throws error if invalid newEditorFlags = []; for (const [flag, value] of Object.entries(flagsJson)) { @@ -201,7 +193,7 @@
- +