mirror of
https://github.com/LukeHagar/OpenAPI.gg.git
synced 2025-12-06 12:37:48 +00:00
Adjusted save logic
This commit is contained in:
12
src/lib/components/FileManagement/LoadButton.svelte
Normal file
12
src/lib/components/FileManagement/LoadButton.svelte
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { setSpec, type APISpec } from '$lib/db';
|
||||||
|
|
||||||
|
export let spec: APISpec;
|
||||||
|
|
||||||
|
function onLoad(e: Event): void {
|
||||||
|
console.log('load button clicked');
|
||||||
|
setSpec(spec);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button class="btn variant-ghost-warning" on:click={onLoad}> Load </button>
|
||||||
19
src/lib/components/FileManagement/SaveNewButton.svelte
Normal file
19
src/lib/components/FileManagement/SaveNewButton.svelte
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { openApiStore } from '$lib';
|
||||||
|
import { db, selectedSpec } from '$lib/db';
|
||||||
|
|
||||||
|
function onSave(e: Event): void {
|
||||||
|
console.log('Save button clicked');
|
||||||
|
if (!$selectedSpec) {
|
||||||
|
$selectedSpec = {
|
||||||
|
name: 'New OpenAPI Spec',
|
||||||
|
spec: $openApiStore
|
||||||
|
};
|
||||||
|
}
|
||||||
|
console.log($selectedSpec);
|
||||||
|
$selectedSpec.id = undefined;
|
||||||
|
db.apiSpecs.put($selectedSpec);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button class="btn variant-ghost-success" on:click={onSave}> Save New </button>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { openApiStore } from '$lib';
|
import { openApiStore } from '$lib';
|
||||||
import { db, selectedSpec } from '$lib/db';
|
import { db, selectedSpec, setSpec } from '$lib/db';
|
||||||
import type { OpenAPIV3_1 } from '$lib/openAPITypes';
|
import type { OpenAPIV3_1 } from '$lib/openAPITypes';
|
||||||
import {
|
import {
|
||||||
FileButton,
|
FileButton,
|
||||||
@@ -29,11 +29,7 @@
|
|||||||
} else {
|
} else {
|
||||||
content = parse(result);
|
content = parse(result);
|
||||||
}
|
}
|
||||||
openApiStore.set(content);
|
setSpec({ name: file.name, spec: content });
|
||||||
selectedSpec.set({
|
|
||||||
name: file.name,
|
|
||||||
spec: content
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error parsing ${isJson ? 'json' : 'yaml'} file`, error);
|
console.error(`Error parsing ${isJson ? 'json' : 'yaml'} file`, error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,19 +5,10 @@ import { writable, type Writable } from "svelte/store";
|
|||||||
|
|
||||||
export const selectedSpec: Writable<APISpec | undefined> = writable(undefined)
|
export const selectedSpec: Writable<APISpec | undefined> = writable(undefined)
|
||||||
|
|
||||||
openApiStore.subscribe((value) => {
|
export const setSpec = (spec: APISpec) => {
|
||||||
if (selectedSpec) {
|
selectedSpec.set(spec);
|
||||||
selectedSpec.update((v) => {
|
openApiStore.set(spec.spec);
|
||||||
if (v) {
|
|
||||||
return {
|
|
||||||
...v,
|
|
||||||
spec: value
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return v;
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export interface APISpec {
|
export interface APISpec {
|
||||||
id?: string;
|
id?: string;
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import CreateNewButton from '$lib/components/FileManagement/CreateNewButton.svelte';
|
import CreateNewButton from '$lib/components/FileManagement/CreateNewButton.svelte';
|
||||||
import DeleteButton from '$lib/components/FileManagement/DeleteButton.svelte';
|
import DeleteButton from '$lib/components/FileManagement/DeleteButton.svelte';
|
||||||
|
import LoadButton from '$lib/components/FileManagement/LoadButton.svelte';
|
||||||
import SaveButton from '$lib/components/FileManagement/SaveButton.svelte';
|
import SaveButton from '$lib/components/FileManagement/SaveButton.svelte';
|
||||||
|
import SaveNewButton from '$lib/components/FileManagement/SaveNewButton.svelte';
|
||||||
import Upload from '$lib/components/FileManagement/Upload.svelte';
|
import Upload from '$lib/components/FileManagement/Upload.svelte';
|
||||||
import { db, selectedSpec } from '$lib/db';
|
import { db, selectedSpec } from '$lib/db';
|
||||||
import { liveQuery } from 'dexie';
|
import { liveQuery } from 'dexie';
|
||||||
@@ -26,6 +28,7 @@
|
|||||||
<td>{spec.id}</td>
|
<td>{spec.id}</td>
|
||||||
<td>{spec.name}</td>
|
<td>{spec.name}</td>
|
||||||
<td>
|
<td>
|
||||||
|
<LoadButton {spec} />
|
||||||
<DeleteButton {spec} />
|
<DeleteButton {spec} />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -33,7 +36,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{#if $selectedSpec?.name}
|
{#if $selectedSpec}
|
||||||
<input
|
<input
|
||||||
class="input"
|
class="input"
|
||||||
bind:value={$selectedSpec.name}
|
bind:value={$selectedSpec.name}
|
||||||
@@ -42,6 +45,7 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
<SaveButton />
|
<SaveButton />
|
||||||
|
<SaveNewButton />
|
||||||
<CreateNewButton />
|
<CreateNewButton />
|
||||||
<Upload />
|
<Upload />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user