diff --git a/web/source/settings/components/form/inputs.jsx b/web/source/settings/components/form/inputs.jsx
index 1081ead75..050577134 100644
--- a/web/source/settings/components/form/inputs.jsx
+++ b/web/source/settings/components/form/inputs.jsx
@@ -90,12 +90,30 @@ function Checkbox({label, field, ...inputProps}) {
);
+}
+function Select({label, field, options, ...inputProps}) {
+ const {onChange, value} = field;
+
+ return (
+
+
+
+ );
}
module.exports = {
TextInput,
TextArea,
FileInput,
- Checkbox
+ Checkbox,
+ Select
};
\ No newline at end of file
diff --git a/web/source/settings/lib/form/bool.jsx b/web/source/settings/lib/form/bool.jsx
index 5553a269b..a25989a08 100644
--- a/web/source/settings/lib/form/bool.jsx
+++ b/web/source/settings/lib/form/bool.jsx
@@ -23,6 +23,8 @@ const React = require("react");
module.exports = function useBoolInput({name, Name}, {defaultValue=false} = {}) {
const [value, setValue] = React.useState(defaultValue);
+ console.log("bool", name, value, defaultValue);
+
function onChange(e) {
setValue(e.target.checked);
}
@@ -40,6 +42,7 @@ module.exports = function useBoolInput({name, Name}, {defaultValue=false} = {})
[`set${Name}`]: setValue
}
], {
+ name,
onChange,
reset,
value,
diff --git a/web/source/settings/lib/form/combobox.jsx b/web/source/settings/lib/form/combobox.jsx
index aeee38fc2..f61bca986 100644
--- a/web/source/settings/lib/form/combobox.jsx
+++ b/web/source/settings/lib/form/combobox.jsx
@@ -20,7 +20,7 @@
const { useComboboxState } = require("ariakit/combobox");
-module.exports = function useComboBoxInput({name, Name}, {validator, defaultValue} = {}) {
+module.exports = function useComboBoxInput({name, Name}, {defaultValue} = {}) {
const state = useComboboxState({
defaultValue,
gutter: 0,
@@ -31,11 +31,16 @@ module.exports = function useComboBoxInput({name, Name}, {validator, defaultValu
state.setValue("");
}
- return [
+ return Object.assign([
state,
reset,
+ name,
{
[name]: state.value,
}
- ];
+ ], {
+ name,
+ value: state.value,
+ reset
+ });
};
\ No newline at end of file
diff --git a/web/source/settings/lib/form/file.jsx b/web/source/settings/lib/form/file.jsx
index 64433c132..e6492198c 100644
--- a/web/source/settings/lib/form/file.jsx
+++ b/web/source/settings/lib/form/file.jsx
@@ -82,6 +82,7 @@ module.exports = function useFileInput({name, _Name}, {
], {
onChange,
reset,
+ name,
value: file,
previewValue: imageURL,
hasChanged: () => file != undefined,
diff --git a/web/source/settings/lib/form/submit.js b/web/source/settings/lib/form/submit.js
index 8a2a1fad7..ebb3068ce 100644
--- a/web/source/settings/lib/form/submit.js
+++ b/web/source/settings/lib/form/submit.js
@@ -29,11 +29,11 @@ module.exports = function useFormSubmit(form, [mutationQuery, result]) {
// transform the field definitions into an object with just their values
let updatedFields = [];
const mutationData = syncpipe(form, [
- (_) => Object.entries(_),
- (_) => _.map(([key, field]) => {
+ (_) => Object.values(_),
+ (_) => _.map((field) => {
if (field.hasChanged()) {
updatedFields.push(field);
- return [key, field.value];
+ return [field.name, field.value];
} else {
return null;
}
diff --git a/web/source/settings/lib/form/text.jsx b/web/source/settings/lib/form/text.jsx
index 6b3ad14fe..6b3ca5495 100644
--- a/web/source/settings/lib/form/text.jsx
+++ b/web/source/settings/lib/form/text.jsx
@@ -56,6 +56,7 @@ module.exports = function useTextInput({name, Name}, {validator, defaultValue=""
], {
onChange,
reset,
+ name,
value: text,
ref: textRef,
setter: setText,
diff --git a/web/source/settings/user/profile.js b/web/source/settings/user/profile.js
index f9bab9623..43d7314ad 100644
--- a/web/source/settings/user/profile.js
+++ b/web/source/settings/user/profile.js
@@ -43,10 +43,16 @@ const MutationButton = require("../components/form/mutation-button");
const Loading = require("../components/loading");
module.exports = function UserProfile() {
- const allowCustomCSS = Redux.useSelector(state => state.instances.current.configuration.accounts.allow_custom_css);
- // const profile = Redux.useSelector(state => state.user.profile);
const {data: profile = {}, isLoading} = query.useVerifyCredentialsQuery();
+ if (isLoading) {
+ return ;
+ } else {
+ return ;
+ }
+};
+
+function UserProfileForm({profile}) {
/*
User profile update form keys
- bool bot
@@ -55,10 +61,6 @@ module.exports = function UserProfile() {
- string note
- file avatar
- file header
- - string source[privacy]
- - bool source[sensitive]
- - string source[language]
- - string source[status_format]
- bool enable_rss
- string custom_css (if enabled)
*/
@@ -66,21 +68,17 @@ module.exports = function UserProfile() {
const form = {
avatar: useFileInput("avatar", {withPreview: true, }),
header: useFileInput("header", {withPreview: true, }),
- display_name: useTextInput("displayName", {defaultValue: profile.display_name}),
+ displayName: useTextInput("display_name", {defaultValue: profile.display_name}),
note: useTextInput("note", {defaultValue: profile.source?.note}),
- custom_css: useTextInput("customCSS", {defaultValue: profile.custom_css}),
- bot: useBoolInput("isBot", {defaultValue: profile.bot}),
- locked: useBoolInput("isLocked", {defaultValue: profile.locked}),
- enable_rss: useBoolInput("enableRSS", {defaultValue: profile.enable_rss}),
- "source[sensitive]": useBoolInput("isSensitive", {defaultValue: profile.source?.sensitive}),
+ customCSS: useTextInput("custom_css", {defaultValue: profile.custom_css}),
+ bot: useBoolInput("bot", {defaultValue: profile.bot}),
+ locked: useBoolInput("locked", {defaultValue: profile.locked}),
+ enableRSS: useBoolInput("enable_rss", {defaultValue: profile.enable_rss}),
};
+ const allowCustomCSS = Redux.useSelector(state => state.instances.current.configuration.accounts.allow_custom_css);
const [result, submitForm] = useFormSubmit(form, query.useUpdateCredentialsMutation());
- if (isLoading) {
- return ;
- }
-
return (
);
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/web/source/settings/user/settings.js b/web/source/settings/user/settings.js
index 59994ede3..d42e9ff91 100644
--- a/web/source/settings/user/settings.js
+++ b/web/source/settings/user/settings.js
@@ -23,37 +23,64 @@ const React = require("react");
const Redux = require("react-redux");
const api = require("../lib/api");
-const user = require("../redux/reducers/user").actions;
-const submit = require("../lib/submit");
const Languages = require("../components/languages");
const Submit = require("../components/submit");
+const query = require("../lib/query");
+
+const {
+ useTextInput,
+ useBoolInput
+} = require("../lib/form");
+
+const useFormSubmit = require("../lib/form/submit");
+
const {
- Checkbox,
Select,
-} = require("../components/form-fields").formFields(user.setSettingsVal, (state) => state.user.settings);
+ TextInput,
+ Checkbox
+} = require("../components/form/inputs");
+
+const MutationButton = require("../components/form/mutation-button");
+const Loading = require("../components/loading");
module.exports = function UserSettings() {
- const dispatch = Redux.useDispatch();
+ const {data: profile, isLoading} = query.useVerifyCredentialsQuery();
- const [errorMsg, setError] = React.useState("");
- const [statusMsg, setStatus] = React.useState("");
+ if (isLoading) {
+ return ;
+ } else {
+ return ;
+ }
+};
- const updateSettings = submit(
- () => dispatch(api.user.updateSettings()),
- {setStatus, setError}
- );
+function UserSettingsForm({source}) {
+ /* form keys
+ - string source[privacy]
+ - bool source[sensitive]
+ - string source[language]
+ - string source[status_format]
+ */
+
+ const form = {
+ defaultPrivacy: useTextInput("source[privacy]", {defaultValue: source.privacy ?? "unlisted"}),
+ isSensitive: useBoolInput("source[sensitive]", {defaultValue: source.sensitive}),
+ language: useTextInput("source[language]", {defaultValue: source.language ?? "EN"}),
+ format: useTextInput("source[status_format]", {defaultValue: source.status_format ?? "plain"}),
+ };
+
+ const [result, submitForm] = useFormSubmit(form, query.useUpdateCredentialsMutation());
return (
<>
-
+
+
>
);
-};
+}
function PasswordChange() {
const dispatch = Redux.useDispatch();