refactor user post settings
This commit is contained in:
parent
d579b4476d
commit
e924566add
|
@ -90,12 +90,30 @@ function Checkbox({label, field, ...inputProps}) {
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Select({label, field, options, ...inputProps}) {
|
||||||
|
const {onChange, value} = field;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="form-field select">
|
||||||
|
<label>
|
||||||
|
{label}
|
||||||
|
<select
|
||||||
|
{...{onChange, value}}
|
||||||
|
{...inputProps}
|
||||||
|
>
|
||||||
|
{options}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
TextInput,
|
TextInput,
|
||||||
TextArea,
|
TextArea,
|
||||||
FileInput,
|
FileInput,
|
||||||
Checkbox
|
Checkbox,
|
||||||
|
Select
|
||||||
};
|
};
|
|
@ -23,6 +23,8 @@ const React = require("react");
|
||||||
module.exports = function useBoolInput({name, Name}, {defaultValue=false} = {}) {
|
module.exports = function useBoolInput({name, Name}, {defaultValue=false} = {}) {
|
||||||
const [value, setValue] = React.useState(defaultValue);
|
const [value, setValue] = React.useState(defaultValue);
|
||||||
|
|
||||||
|
console.log("bool", name, value, defaultValue);
|
||||||
|
|
||||||
function onChange(e) {
|
function onChange(e) {
|
||||||
setValue(e.target.checked);
|
setValue(e.target.checked);
|
||||||
}
|
}
|
||||||
|
@ -40,6 +42,7 @@ module.exports = function useBoolInput({name, Name}, {defaultValue=false} = {})
|
||||||
[`set${Name}`]: setValue
|
[`set${Name}`]: setValue
|
||||||
}
|
}
|
||||||
], {
|
], {
|
||||||
|
name,
|
||||||
onChange,
|
onChange,
|
||||||
reset,
|
reset,
|
||||||
value,
|
value,
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
const { useComboboxState } = require("ariakit/combobox");
|
const { useComboboxState } = require("ariakit/combobox");
|
||||||
|
|
||||||
module.exports = function useComboBoxInput({name, Name}, {validator, defaultValue} = {}) {
|
module.exports = function useComboBoxInput({name, Name}, {defaultValue} = {}) {
|
||||||
const state = useComboboxState({
|
const state = useComboboxState({
|
||||||
defaultValue,
|
defaultValue,
|
||||||
gutter: 0,
|
gutter: 0,
|
||||||
|
@ -31,11 +31,16 @@ module.exports = function useComboBoxInput({name, Name}, {validator, defaultValu
|
||||||
state.setValue("");
|
state.setValue("");
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return Object.assign([
|
||||||
state,
|
state,
|
||||||
reset,
|
reset,
|
||||||
|
name,
|
||||||
{
|
{
|
||||||
[name]: state.value,
|
[name]: state.value,
|
||||||
}
|
}
|
||||||
];
|
], {
|
||||||
|
name,
|
||||||
|
value: state.value,
|
||||||
|
reset
|
||||||
|
});
|
||||||
};
|
};
|
|
@ -82,6 +82,7 @@ module.exports = function useFileInput({name, _Name}, {
|
||||||
], {
|
], {
|
||||||
onChange,
|
onChange,
|
||||||
reset,
|
reset,
|
||||||
|
name,
|
||||||
value: file,
|
value: file,
|
||||||
previewValue: imageURL,
|
previewValue: imageURL,
|
||||||
hasChanged: () => file != undefined,
|
hasChanged: () => file != undefined,
|
||||||
|
|
|
@ -29,11 +29,11 @@ module.exports = function useFormSubmit(form, [mutationQuery, result]) {
|
||||||
// transform the field definitions into an object with just their values
|
// transform the field definitions into an object with just their values
|
||||||
let updatedFields = [];
|
let updatedFields = [];
|
||||||
const mutationData = syncpipe(form, [
|
const mutationData = syncpipe(form, [
|
||||||
(_) => Object.entries(_),
|
(_) => Object.values(_),
|
||||||
(_) => _.map(([key, field]) => {
|
(_) => _.map((field) => {
|
||||||
if (field.hasChanged()) {
|
if (field.hasChanged()) {
|
||||||
updatedFields.push(field);
|
updatedFields.push(field);
|
||||||
return [key, field.value];
|
return [field.name, field.value];
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,7 @@ module.exports = function useTextInput({name, Name}, {validator, defaultValue=""
|
||||||
], {
|
], {
|
||||||
onChange,
|
onChange,
|
||||||
reset,
|
reset,
|
||||||
|
name,
|
||||||
value: text,
|
value: text,
|
||||||
ref: textRef,
|
ref: textRef,
|
||||||
setter: setText,
|
setter: setText,
|
||||||
|
|
|
@ -43,10 +43,16 @@ const MutationButton = require("../components/form/mutation-button");
|
||||||
const Loading = require("../components/loading");
|
const Loading = require("../components/loading");
|
||||||
|
|
||||||
module.exports = function UserProfile() {
|
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();
|
const {data: profile = {}, isLoading} = query.useVerifyCredentialsQuery();
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return <Loading/>;
|
||||||
|
} else {
|
||||||
|
return <UserProfileForm profile={profile} />;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function UserProfileForm({profile}) {
|
||||||
/*
|
/*
|
||||||
User profile update form keys
|
User profile update form keys
|
||||||
- bool bot
|
- bool bot
|
||||||
|
@ -55,10 +61,6 @@ module.exports = function UserProfile() {
|
||||||
- string note
|
- string note
|
||||||
- file avatar
|
- file avatar
|
||||||
- file header
|
- file header
|
||||||
- string source[privacy]
|
|
||||||
- bool source[sensitive]
|
|
||||||
- string source[language]
|
|
||||||
- string source[status_format]
|
|
||||||
- bool enable_rss
|
- bool enable_rss
|
||||||
- string custom_css (if enabled)
|
- string custom_css (if enabled)
|
||||||
*/
|
*/
|
||||||
|
@ -66,21 +68,17 @@ module.exports = function UserProfile() {
|
||||||
const form = {
|
const form = {
|
||||||
avatar: useFileInput("avatar", {withPreview: true, }),
|
avatar: useFileInput("avatar", {withPreview: true, }),
|
||||||
header: useFileInput("header", {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}),
|
note: useTextInput("note", {defaultValue: profile.source?.note}),
|
||||||
custom_css: useTextInput("customCSS", {defaultValue: profile.custom_css}),
|
customCSS: useTextInput("custom_css", {defaultValue: profile.custom_css}),
|
||||||
bot: useBoolInput("isBot", {defaultValue: profile.bot}),
|
bot: useBoolInput("bot", {defaultValue: profile.bot}),
|
||||||
locked: useBoolInput("isLocked", {defaultValue: profile.locked}),
|
locked: useBoolInput("locked", {defaultValue: profile.locked}),
|
||||||
enable_rss: useBoolInput("enableRSS", {defaultValue: profile.enable_rss}),
|
enableRSS: useBoolInput("enable_rss", {defaultValue: profile.enable_rss}),
|
||||||
"source[sensitive]": useBoolInput("isSensitive", {defaultValue: profile.source?.sensitive}),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const allowCustomCSS = Redux.useSelector(state => state.instances.current.configuration.accounts.allow_custom_css);
|
||||||
const [result, submitForm] = useFormSubmit(form, query.useUpdateCredentialsMutation());
|
const [result, submitForm] = useFormSubmit(form, query.useUpdateCredentialsMutation());
|
||||||
|
|
||||||
if (isLoading) {
|
|
||||||
return <Loading/>;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form className="user-profile" onSubmit={submitForm}>
|
<form className="user-profile" onSubmit={submitForm}>
|
||||||
<h1>Profile</h1>
|
<h1>Profile</h1>
|
||||||
|
@ -88,7 +86,7 @@ module.exports = function UserProfile() {
|
||||||
<FakeProfile
|
<FakeProfile
|
||||||
avatar={form.avatar.previewValue ?? profile.avatar}
|
avatar={form.avatar.previewValue ?? profile.avatar}
|
||||||
header={form.header.previewValue ?? profile.header}
|
header={form.header.previewValue ?? profile.header}
|
||||||
display_name={form.display_name.value ?? profile.username}
|
display_name={form.displayName.value ?? profile.username}
|
||||||
username={profile.username}
|
username={profile.username}
|
||||||
role={profile.role}
|
role={profile.role}
|
||||||
/>
|
/>
|
||||||
|
@ -110,7 +108,7 @@ module.exports = function UserProfile() {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<TextInput
|
<TextInput
|
||||||
field={form.display_name}
|
field={form.displayName}
|
||||||
label="Name"
|
label="Name"
|
||||||
placeholder="A GoToSocial user"
|
placeholder="A GoToSocial user"
|
||||||
/>
|
/>
|
||||||
|
@ -125,12 +123,12 @@ module.exports = function UserProfile() {
|
||||||
label="Manually approve follow requests"
|
label="Manually approve follow requests"
|
||||||
/>
|
/>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
field={form.enable_rss}
|
field={form.enableRSS}
|
||||||
label="Enable RSS feed of Public posts"
|
label="Enable RSS feed of Public posts"
|
||||||
/>
|
/>
|
||||||
{ !allowCustomCSS ? null :
|
{ !allowCustomCSS ? null :
|
||||||
<TextArea
|
<TextArea
|
||||||
field={form.custom_css}
|
field={form.customCSS}
|
||||||
label="Custom CSS"
|
label="Custom CSS"
|
||||||
className="monospace"
|
className="monospace"
|
||||||
rows={8}
|
rows={8}
|
||||||
|
@ -141,4 +139,4 @@ module.exports = function UserProfile() {
|
||||||
<MutationButton text="Save profile info" result={result}/>
|
<MutationButton text="Save profile info" result={result}/>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
};
|
}
|
|
@ -23,37 +23,64 @@ const React = require("react");
|
||||||
const Redux = require("react-redux");
|
const Redux = require("react-redux");
|
||||||
|
|
||||||
const api = require("../lib/api");
|
const api = require("../lib/api");
|
||||||
const user = require("../redux/reducers/user").actions;
|
|
||||||
const submit = require("../lib/submit");
|
|
||||||
|
|
||||||
const Languages = require("../components/languages");
|
const Languages = require("../components/languages");
|
||||||
const Submit = require("../components/submit");
|
const Submit = require("../components/submit");
|
||||||
|
|
||||||
|
const query = require("../lib/query");
|
||||||
|
|
||||||
|
const {
|
||||||
|
useTextInput,
|
||||||
|
useBoolInput
|
||||||
|
} = require("../lib/form");
|
||||||
|
|
||||||
|
const useFormSubmit = require("../lib/form/submit");
|
||||||
|
|
||||||
const {
|
const {
|
||||||
Checkbox,
|
|
||||||
Select,
|
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() {
|
module.exports = function UserSettings() {
|
||||||
const dispatch = Redux.useDispatch();
|
const {data: profile, isLoading} = query.useVerifyCredentialsQuery();
|
||||||
|
|
||||||
const [errorMsg, setError] = React.useState("");
|
if (isLoading) {
|
||||||
const [statusMsg, setStatus] = React.useState("");
|
return <Loading/>;
|
||||||
|
} else {
|
||||||
|
return <UserSettingsForm source={profile.source} />;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const updateSettings = submit(
|
function UserSettingsForm({source}) {
|
||||||
() => dispatch(api.user.updateSettings()),
|
/* form keys
|
||||||
{setStatus, setError}
|
- 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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="user-settings">
|
<form className="user-settings" onSubmit={submitForm}>
|
||||||
<h1>Post settings</h1>
|
<h1>Post settings</h1>
|
||||||
<Select id="source.language" name="Default post language" options={
|
<Select field={form.language} label="Default post language" options={
|
||||||
<Languages/>
|
<Languages/>
|
||||||
}>
|
}>
|
||||||
</Select>
|
</Select>
|
||||||
<Select id="source.privacy" name="Default post privacy" options={
|
<Select field={form.defaultPrivacy} label="Default post privacy" options={
|
||||||
<>
|
<>
|
||||||
<option value="private">Private / followers-only</option>
|
<option value="private">Private / followers-only</option>
|
||||||
<option value="unlisted">Unlisted</option>
|
<option value="unlisted">Unlisted</option>
|
||||||
|
@ -62,7 +89,7 @@ module.exports = function UserSettings() {
|
||||||
}>
|
}>
|
||||||
<a href="https://docs.gotosocial.org/en/latest/user_guide/posts/#privacy-settings" target="_blank" className="moreinfolink" rel="noreferrer">Learn more about post privacy settings (opens in a new tab)</a>
|
<a href="https://docs.gotosocial.org/en/latest/user_guide/posts/#privacy-settings" target="_blank" className="moreinfolink" rel="noreferrer">Learn more about post privacy settings (opens in a new tab)</a>
|
||||||
</Select>
|
</Select>
|
||||||
<Select id="source.status_format" name="Default post (and bio) format" options={
|
<Select field={form.format} label="Default post (and bio) format" options={
|
||||||
<>
|
<>
|
||||||
<option value="plain">Plain (default)</option>
|
<option value="plain">Plain (default)</option>
|
||||||
<option value="markdown">Markdown</option>
|
<option value="markdown">Markdown</option>
|
||||||
|
@ -71,18 +98,18 @@ module.exports = function UserSettings() {
|
||||||
<a href="https://docs.gotosocial.org/en/latest/user_guide/posts/#input-types" target="_blank" className="moreinfolink" rel="noreferrer">Learn more about post format settings (opens in a new tab)</a>
|
<a href="https://docs.gotosocial.org/en/latest/user_guide/posts/#input-types" target="_blank" className="moreinfolink" rel="noreferrer">Learn more about post format settings (opens in a new tab)</a>
|
||||||
</Select>
|
</Select>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
id="source.sensitive"
|
field={form.isSensitive}
|
||||||
name="Mark my posts as sensitive by default"
|
label="Mark my posts as sensitive by default"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Submit onClick={updateSettings} label="Save post settings" errorMsg={errorMsg} statusMsg={statusMsg}/>
|
<MutationButton text="Save settings" result={result}/>
|
||||||
</div>
|
</form>
|
||||||
<div>
|
<div>
|
||||||
<PasswordChange/>
|
<PasswordChange/>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
function PasswordChange() {
|
function PasswordChange() {
|
||||||
const dispatch = Redux.useDispatch();
|
const dispatch = Redux.useDispatch();
|
||||||
|
|
Loading…
Reference in New Issue