diff options
| author | Fuwn <[email protected]> | 2024-02-12 09:27:30 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-02-12 09:27:30 -0800 |
| commit | 81e6a9e431f9c6a109d7f4052f6af9a6d5bc6498 (patch) | |
| tree | 488e33511a9ac93f0ec40fa00ae2d75ffb082355 /src/lib/Settings | |
| parent | feat(settings): localise settings sync (diff) | |
| download | due.moe-81e6a9e431f9c6a109d7f4052f6af9a6d5bc6498.tar.xz due.moe-81e6a9e431f9c6a109d7f4052f6af9a6d5bc6498.zip | |
refactor(settings): move settings sync to component
Diffstat (limited to 'src/lib/Settings')
| -rw-r--r-- | src/lib/Settings/Categories/SettingSync.svelte | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/lib/Settings/Categories/SettingSync.svelte b/src/lib/Settings/Categories/SettingSync.svelte new file mode 100644 index 00000000..54962b44 --- /dev/null +++ b/src/lib/Settings/Categories/SettingSync.svelte @@ -0,0 +1,90 @@ +<script lang="ts"> + import { options } from '$lib/Notification/options'; + import root from '$lib/Utility/root'; + import identity from '$stores/identity'; + import settings from '$stores/settings'; + import { getNotificationsContext } from 'svelte-notifications'; + import SettingHint from '../SettingHint.svelte'; + import locale from '$stores/locale'; + + const { addNotification } = getNotificationsContext(); +</script> + +{#if !$settings.settingsSync} + <button + on:click={() => { + $settings.settingsSync = true; + + fetch(root(`/api/configuration?id=${$identity.id}`)).then((response) => { + if (response.ok) { + response.json().then((data) => { + if (data && data.configuration) { + $settings = data.configuration; + + addNotification( + options({ + heading: 'Pulled remote configuration' + }) + ); + } else { + fetch(root(`/api/configuration`), { + method: 'PUT', + body: JSON.stringify($settings) + }).then((response) => { + if (response.ok) + addNotification( + options({ + heading: 'Created remote configuration' + }) + ); + }); + } + }); + } + }); + }} + > + {$locale().settings.settingsSync.buttons.pull.title} + </button> + <SettingHint lineBreak> + {$locale().settings.settingsSync.buttons.pull.hint} + </SettingHint> + <p /> + <button + on:click={() => { + $settings.settingsSync = true; + + fetch(root(`/api/configuration`), { + method: 'PUT', + body: JSON.stringify($settings) + }).then((response) => { + if (response.ok) + addNotification( + options({ + heading: 'Settings Sync', + description: 'Pushed local configuration to remote' + }) + ); + }); + }} + > + {$locale().settings.settingsSync.buttons.push.title} + </button> + <SettingHint lineBreak> + {$locale().settings.settingsSync.buttons.push.hint} + </SettingHint> +{:else} + <button + on:click={() => { + $settings.settingsSync = false; + + addNotification( + options({ + heading: 'Settings sync disabled' + }) + ); + }} + > + {$locale().settings.settingsSync.buttons.disable} + </button> +{/if} |