mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-22 08:46:00 +00:00
settings WIP
This commit is contained in:
42
packages/web/src/forms/SettingsFormProvider.svelte
Normal file
42
packages/web/src/forms/SettingsFormProvider.svelte
Normal file
@@ -0,0 +1,42 @@
|
||||
<script lang="ts" context="module">
|
||||
import { getContext, setContext } from 'svelte';
|
||||
|
||||
const contextKey = 'formProviderContextKey';
|
||||
|
||||
export function getFormContext(): any {
|
||||
return getContext(contextKey);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import FormFieldTemplateLarge from './FormFieldTemplateLarge.svelte';
|
||||
import createRef from '../utility/createRef';
|
||||
import { apiCall } from '../utility/api';
|
||||
import { useSettings } from '../utility/metadataLoaders';
|
||||
import { derived } from 'svelte/store';
|
||||
|
||||
export let template = FormFieldTemplateLarge;
|
||||
|
||||
const settings = useSettings();
|
||||
const values = derived(settings, $settings => {
|
||||
if (!$settings) {
|
||||
return {};
|
||||
}
|
||||
return $settings;
|
||||
});
|
||||
|
||||
const setFieldValue = (name, value) => {
|
||||
apiCall('config/update-settings', { [name]: value });
|
||||
};
|
||||
|
||||
const context = {
|
||||
values,
|
||||
template,
|
||||
setFieldValue,
|
||||
submitActionRef: createRef(null),
|
||||
};
|
||||
|
||||
setContext(contextKey, context);
|
||||
</script>
|
||||
|
||||
<slot />
|
||||
Reference in New Issue
Block a user