Skip to content

Commit

Permalink
[frontend] Better autocapitalize/spellcheck settings on forms (#3077)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmethurst authored Jul 8, 2024
1 parent 5769722 commit bbbf6eb
Show file tree
Hide file tree
Showing 20 changed files with 205 additions and 38 deletions.
32 changes: 29 additions & 3 deletions web/source/settings/views/admin/actions/keys/expireremote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,33 @@ import { TextInput } from "../../../../components/form/inputs";
import MutationButton from "../../../../components/form/mutation-button";
import { useTextInput } from "../../../../lib/form";
import { useInstanceKeysExpireMutation } from "../../../../lib/query/admin/actions";
import isValidDomain from "is-valid-domain";

export default function ExpireRemote({}) {
const domainField = useTextInput("domain");
const domainField = useTextInput("domain", {
validator: (v: string) => {
if (v.length === 0) {
return "";
}

if (v[v.length-1] === ".") {
return "invalid domain";
}

const valid = isValidDomain(v, {
subdomain: true,
wildcard: false,
allowUnicode: true,
topLevel: false,
});

if (valid) {
return "";
}

return "invalid domain";
}
});

const [expire, expireResult] = useInstanceKeysExpireMutation();

Expand Down Expand Up @@ -52,11 +76,13 @@ export default function ExpireRemote({}) {
<TextInput
field={domainField}
label="Domain"
type="string"
type="text"
autoCapitalize="none"
spellCheck="false"
placeholder="example.org"
/>
<MutationButton
disabled={!domainField.value}
disabled={!domainField.value || !domainField.valid}
label="Expire keys"
result={expireResult}
/>
Expand Down
3 changes: 3 additions & 0 deletions web/source/settings/views/admin/debug/apurl/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export default function ApURL() {
<TextInput
field={urlField}
label="URL"
type="url"
pattern="(http|https):\/\/.+"
placeholder="https://example.org/users/someone"
/>
<MutationButton
disabled={!urlField.value}
Expand Down
2 changes: 2 additions & 0 deletions web/source/settings/views/admin/emoji/category-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ export function CategorySelect({ field, children }: PropsWithChildren<CategorySe
items={categoryItems}
label="Category"
placeholder="e.g., reactions"
autoCapitalize="none"
spellCheck="false"
>
{children}
</ComboBox>
Expand Down
2 changes: 2 additions & 0 deletions web/source/settings/views/admin/emoji/local/new-emoji.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export default function NewEmojiForm() {
<TextInput
field={form.shortcode}
label="Shortcode, must be unique among the instance's local emoji"
autoCapitalize="none"
spellCheck="false"
{...{pattern: "^\\w{2,30}$"}}
/>

Expand Down
2 changes: 2 additions & 0 deletions web/source/settings/views/admin/emoji/local/overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ function EmojiList({ emoji }: EmojiListParams) {
field={filterField}
name="emoji-shortcode"
placeholder="Search"
autoCapitalize="none"
spellCheck="false"
/>
</div>
<div className="entries scrolling">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ export default function StealThisLook({ emojiCodes }) {
</label>
<div className="row">
<input
type="text"
id="url"
name="url"
type="url"
pattern="(http|https):\/\/.+"
onChange={urlField.onChange}
value={urlField.value}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default function HeaderPermCreateForm({ permType }: { permType: PermType
field={form.header}
label={
<>
HTTP Header Name&nbsp;
Header Name&nbsp;
<a
href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers"
target="_blank"
Expand All @@ -112,12 +112,15 @@ export default function HeaderPermCreateForm({ permType }: { permType: PermType
</>
}
placeholder={"User-Agent"}
autoCapitalize="none"
spellCheck="false"
{...{className: "monospace"}}
/>
<TextInput
field={form.regex}
label={
<>
HTTP Header Value RE2 Regex&nbsp;
Value Regex&nbsp;
<a
href="https://github.com/google/re2/wiki/Syntax"
target="_blank"
Expand All @@ -129,6 +132,8 @@ export default function HeaderPermCreateForm({ permType }: { permType: PermType
</>
}
placeholder={"^.*Some-User-Agent.*$"}
autoCapitalize="none"
spellCheck="false"
{...{className: "monospace"}}
/>
<MutationButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function PermDeets({
<dl className="info-list">
<div className="info-list-entry">
<dt>ID</dt>
<dd>{perm.id}</dd>
<dd className="monospace">{perm.id}</dd>
</div>
<div className="info-list-entry">
<dt>Created</dt>
Expand All @@ -176,10 +176,10 @@ function PermDeets({
</div>
<div className="info-list-entry">
<dt>Header Name</dt>
<dd>{perm.header}</dd>
<dd className="monospace">{perm.header}</dd>
</div>
<div className="info-list-entry">
<dt>Header Value Regex</dt>
<dt>Value Regex</dt>
<dd className="monospace">{perm.regex}</dd>
</div>
<div className="info-list-entry">
Expand Down
15 changes: 13 additions & 2 deletions web/source/settings/views/admin/instance/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ function InstanceSettingsForm({ data: instance }: InstanceSettingsFormProps) {
const [submitForm, result] = useFormSubmit(form, useUpdateInstanceMutation());

return (
<form onSubmit={submitForm}>
<form
onSubmit={submitForm}
autoComplete="none"
>
<h1>Instance Settings</h1>

<div className="form-section-docs">
Expand All @@ -97,7 +100,8 @@ function InstanceSettingsForm({ data: instance }: InstanceSettingsFormProps) {
<TextInput
field={form.title}
label={`Instance title (max ${titleLimit} characters)`}
placeholder="My GoToSocial instance"
autoCapitalize="words"
placeholder="My GoToSocial Instance"
/>

<div className="file-upload" aria-labelledby="avatar">
Expand All @@ -117,6 +121,7 @@ function InstanceSettingsForm({ data: instance }: InstanceSettingsFormProps) {
field={form.thumbnailDesc}
label="Avatar image description"
placeholder="A cute drawing of a smiling sloth."
autoCapitalize="sentences"
/>
</div>
</div>
Expand All @@ -139,20 +144,23 @@ function InstanceSettingsForm({ data: instance }: InstanceSettingsFormProps) {
field={form.shortDesc}
label={`Short description (markdown accepted, max ${shortDescLimit} characters)`}
placeholder="A small testing instance for the GoToSocial alpha software."
autoCapitalize="sentences"
rows={6}
/>

<TextArea
field={form.description}
label={`Full description (markdown accepted, max ${descLimit} characters)`}
placeholder="A small testing instance for the GoToSocial alpha software. Just trying it out, my main instance is https://example.com"
autoCapitalize="sentences"
rows={6}
/>

<TextArea
field={form.terms}
label={`Terms & Conditions (markdown accepted, max ${termsLimit} characters)`}
placeholder="Terms and conditions of using this instance, data policy, imprint, GDPR stuff, yadda yadda."
autoCapitalize="sentences"
rows={6}
/>

Expand All @@ -172,12 +180,15 @@ function InstanceSettingsForm({ data: instance }: InstanceSettingsFormProps) {
field={form.contactUser}
label="Contact user (local account username)"
placeholder="admin"
autoCapitalize="none"
spellCheck="false"
/>

<TextInput
field={form.contactEmail}
label="Contact email"
placeholder="[email protected]"
type="email"
/>

<MutationButton label="Save" result={result} disabled={false} />
Expand Down
13 changes: 10 additions & 3 deletions web/source/settings/views/moderation/accounts/detail/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,21 @@ function ModerateAccount({ account }: { account: AdminAccount }) {
>
<h3 id="account-moderation-actions">Account Moderation Actions</h3>
<div>
Currently only the "suspend" action is implemented.<br/>
Suspending an account will delete it from your server, and remove all of its media, posts, relationships, etc.<br/>
If the suspended account is local, suspending will also send out a "delete" message to other servers, requesting them to remove its data from their instance as well.<br/>
Currently only the "suspend" action is implemented.
<br/>
Suspending an account will delete it from your server,
and remove all of its media, posts, relationships, etc.
<br/>
If the suspended account is local, suspending will also
send out a "delete" message to other servers, requesting
them to remove its data from their instance as well.
<br/>
<b>Account suspension cannot be reversed.</b>
</div>
<TextInput
field={form.reason}
placeholder="Reason for this action"
autoCapitalize="sentences"
/>
<div className="action-buttons">
<MutationButton
Expand Down
16 changes: 10 additions & 6 deletions web/source/settings/views/moderation/accounts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ import { AccountSearchForm } from "./search";
export default function AccountsSearch({ }) {
return (
<div className="accounts-view">
<h1>Accounts Search</h1>
<span>
You can perform actions on an account by clicking
its name in a report, or by searching for the account
using the form below and clicking on its name.
</span>
<div className="form-section-docs">
<h1>Accounts Search</h1>
<p>
You can perform actions on an account by clicking
its name in a report, or by searching for the account
using the form below and clicking on its name.
<br/>
All fields in the below form are optional.
</p>
</div>
<AccountSearchForm />
</div>
);
Expand Down
18 changes: 17 additions & 1 deletion web/source/settings/views/moderation/accounts/pending/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,23 @@ export default function AccountsPending() {

return (
<div className="accounts-view">
<h1>Pending Accounts</h1>
<div className="form-section-docs">
<h1>Pending Accounts</h1>
<p>
You can see a list of pending account sign-ups below.
<br/>
To approve or reject a sign-up, click on the account's name in the
list, and use the controls at the bottom of the account detail view.
</p>
<a
href="https://docs.gotosocial.org/en/latest/admin/signups/"
target="_blank"
className="docslink"
rel="noreferrer"
>
Learn more about account sign-ups (opens in a new tab)
</a>
</div>
<PageableList
isLoading={searchRes.isLoading}
isFetching={searchRes.isFetching}
Expand Down
44 changes: 38 additions & 6 deletions web/source/settings/views/moderation/accounts/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import MutationButton from "../../../../components/form/mutation-button";
import { useLocation, useSearch } from "wouter";
import { AdminAccount } from "../../../../lib/types/account";
import Username from "../../../../components/username";
import isValidDomain from "is-valid-domain";

export function AccountSearchForm() {
const [ location, setLocation ] = useLocation();
Expand All @@ -42,7 +43,31 @@ export function AccountSearchForm() {
permissions: useTextInput("permissions", { defaultValue: urlQueryParams.get("permissions") ?? ""}),
username: useTextInput("username", { defaultValue: urlQueryParams.get("username") ?? ""}),
display_name: useTextInput("display_name", { defaultValue: urlQueryParams.get("display_name") ?? ""}),
by_domain: useTextInput("by_domain", { defaultValue: urlQueryParams.get("by_domain") ?? ""}),
by_domain: useTextInput("by_domain", {
defaultValue: urlQueryParams.get("by_domain") ?? "",
validator: (v: string) => {
if (v.length === 0) {
return "";
}

if (v[v.length-1] === ".") {
return "invalid domain";
}

const valid = isValidDomain(v, {
subdomain: true,
wildcard: false,
allowUnicode: true,
topLevel: false,
});

if (valid) {
return "";
}

return "invalid domain";
}
}),
email: useTextInput("email", { defaultValue: urlQueryParams.get("email") ?? ""}),
ip: useTextInput("ip", { defaultValue: urlQueryParams.get("ip") ?? ""}),
limit: useTextInput("limit", { defaultValue: urlQueryParams.get("limit") ?? "50"})
Expand Down Expand Up @@ -109,13 +134,17 @@ export function AccountSearchForm() {
>
<TextInput
field={form.username}
label={"(Optional) username (without leading '@' symbol)"}
label={`Username (without "@" prefix) - case sensitive`}
placeholder="someone"
autoCapitalize="none"
spellCheck="false"
/>
<TextInput
field={form.by_domain}
label={"(Optional) domain"}
label={`Domain (without "https://" prefix)`}
placeholder="example.org"
autoCapitalize="none"
spellCheck="false"
/>
<Select
field={form.origin}
Expand All @@ -130,15 +159,18 @@ export function AccountSearchForm() {
></Select>
<TextInput
field={form.email}
label={"(Optional) email address (local accounts only)"}
label={"Email address (local accounts only)"}
placeholder={"[email protected]"}
// Get email validation for free.
{...{type: "email"}}
type="email"
/>
<TextInput
field={form.ip}
label={"(Optional) IP address (local accounts only)"}
label={"IP address (local accounts only)"}
placeholder={"198.51.100.0"}
autoCapitalize="none"
spellCheck="false"
className="monospace"
/>
<Select
field={form.status}
Expand Down
Loading

0 comments on commit bbbf6eb

Please sign in to comment.