CalmEngine: do not wait for success

This commit is contained in:
Liam Fitzgerald 2021-06-16 08:38:59 +10:00
parent 5ba7a2fe52
commit 520da1ed71
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB

View File

@ -3,14 +3,13 @@ import {
Text
} from '@tlon/indigo-react';
import { Form, Formik, FormikHelpers } from 'formik';
import { Form } from 'formik';
import React, { useCallback } from 'react';
import GlobalApi from '~/logic/api/global';
import useSettingsState, { selectSettingsState, SettingsState } from '~/logic/state/settings';
import { AsyncButton } from '~/views/components/AsyncButton';
import useSettingsState, { SettingsState } from '~/logic/state/settings';
import { BackButton } from './BackButton';
import _ from 'lodash';
import {FormikOnBlur} from '~/views/components/FormikOnBlur';
import { FormikOnBlur } from '~/views/components/FormikOnBlur';
interface FormSchema {
hideAvatars: boolean;
@ -36,23 +35,19 @@ const settingsSel = (s: SettingsState): FormSchema => ({
audioShown: !s.remoteContentPolicy.audioShown
});
export function CalmPrefs(props: {
api: GlobalApi;
}) {
const { api } = props;
const initialValues = useSettingsState(settingsSel);
const onSubmit = useCallback(async (v: FormSchema, actions: FormikHelpers<FormSchema>) => {
let promises: Promise<any>[] = [];
const onSubmit = useCallback(async (v: FormSchema) => {
_.forEach(v, (bool, key) => {
const bucket = ['imageShown', 'videoShown', 'audioShown', 'oembedShown'].includes(key) ? 'remoteContentPolicy' : 'calm';
if(initialValues[key] !== bool) {
promises.push(api.settings.putEntry(bucket, key, bool));
api.settings.putEntry(bucket, key, bool);
}
})
await Promise.all(promises);
actions.setStatus({ success: null });
});
}, [api]);
return (