From 92243d58ac661bd1d79f86458f446bd6df532fae Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 30 Mar 2023 15:30:34 +0200 Subject: [PATCH] feat: accept short versions of traditional pronouns --- frontend/src/lib/api/entities.ts | 9 +++++ frontend/src/lib/pronouns.json | 18 +++++++-- frontend/src/routes/edit/profile/+page.svelte | 38 ++++++++++++------- frontend/src/routes/edit/profile/+page.ts | 6 ++- .../routes/pronouns/[...pronouns]/+page.ts | 22 +++++++---- 5 files changed, 67 insertions(+), 26 deletions(-) diff --git a/frontend/src/lib/api/entities.ts b/frontend/src/lib/api/entities.ts index c1f71d5..b2ba0ec 100644 --- a/frontend/src/lib/api/entities.ts +++ b/frontend/src/lib/api/entities.ts @@ -174,3 +174,12 @@ export const defaultAvatars = [ `${PUBLIC_BASE_URL}/default/512.webp`, `${PUBLIC_BASE_URL}/default/512.jpg`, ]; + +export interface PronounsJson { + pages: Pronouns; + autocomplete: Pronouns; +} + +interface Pronouns { + [key: string]: { pronouns: string[]; display?: string }; +} diff --git a/frontend/src/lib/pronouns.json b/frontend/src/lib/pronouns.json index ac48e89..a06df3b 100644 --- a/frontend/src/lib/pronouns.json +++ b/frontend/src/lib/pronouns.json @@ -1,12 +1,22 @@ { - "pronouns": { + "pages": { "they": { "pronouns": ["they", "them", "their", "theirs", "themself"] }, - "they/them": { "pronouns": ["they", "them", "their", "theirs", "themself"] }, "he": { "pronouns": ["he", "him", "his", "his", "himself"] }, - "he/him": { "pronouns": ["he", "him", "his", "his", "himself"] }, "she": { "pronouns": ["she", "her", "her", "hers", "herself"] }, + "it": { "pronouns": ["it", "it", "its", "its", "itself"], "display": "it/its" } + }, + "autocomplete": { + "they/them": { "pronouns": ["they", "them", "their", "theirs", "themself"] }, + "they/them (singular)": { + "pronouns": ["they", "them", "their", "theirs", "themself"], + "display": "they/them (singular)" + }, + "they/them (plural)": { + "pronouns": ["they", "them", "their", "theirs", "themselves"], + "display": "they/them (plural)" + }, + "he/him": { "pronouns": ["he", "him", "his", "his", "himself"] }, "she/her": { "pronouns": ["she", "her", "her", "hers", "herself"] }, - "it": { "pronouns": ["it", "it", "its", "its", "itself"], "display": "it/its" }, "it/its": { "pronouns": ["it", "it", "its", "its", "itself"], "display": "it/its" } } } diff --git a/frontend/src/routes/edit/profile/+page.svelte b/frontend/src/routes/edit/profile/+page.svelte index 5a45782..58c92be 100644 --- a/frontend/src/routes/edit/profile/+page.svelte +++ b/frontend/src/routes/edit/profile/+page.svelte @@ -11,7 +11,7 @@ } from "$lib/api/entities"; import FallbackImage from "$lib/components/FallbackImage.svelte"; import { userStore } from "$lib/store"; - import { Button, ButtonGroup, FormGroup, Icon, Input } from "sveltestrap"; + import { Alert, Button, ButtonGroup, FormGroup, Icon, Input, Popover } from "sveltestrap"; import { encode } from "base64-arraybuffer"; import { apiFetchClient } from "$lib/api/fetch"; import IconButton from "$lib/components/IconButton.svelte"; @@ -40,7 +40,6 @@ let newName = ""; let newPronouns = ""; - let newPronounsDisplay = ""; let newLink = ""; let modified = false; @@ -155,12 +154,23 @@ }; const addPronouns = () => { - pronouns = [ - ...pronouns, - { pronouns: newPronouns, display_text: newPronounsDisplay || null, status: WordStatus.Okay }, - ]; + if (newPronouns in data.pronouns) { + const fullSet = data.pronouns[newPronouns]; + pronouns = [ + ...pronouns, + { + pronouns: fullSet.pronouns.join("/"), + display_text: fullSet.display || null, + status: WordStatus.Okay, + }, + ]; + } else { + pronouns = [ + ...pronouns, + { pronouns: newPronouns, display_text: null, status: WordStatus.Okay }, + ]; + } newPronouns = ""; - newPronounsDisplay = ""; }; const addLink = () => { @@ -353,22 +363,22 @@ - addPronouns()} /> + + + For common pronouns, the short form (e.g. "she/her" or "he/him") is enough; for less + common pronouns, you will have to use all five forms (e.g. "ce/cir/cir/cirs/cirself"). + diff --git a/frontend/src/routes/edit/profile/+page.ts b/frontend/src/routes/edit/profile/+page.ts index 086c87c..1054016 100644 --- a/frontend/src/routes/edit/profile/+page.ts +++ b/frontend/src/routes/edit/profile/+page.ts @@ -1,7 +1,10 @@ -import type { APIError, MeUser } from "$lib/api/entities"; +import type { APIError, MeUser, PronounsJson } from "$lib/api/entities"; import { apiFetchClient } from "$lib/api/fetch"; import { error } from "@sveltejs/kit"; +import pronounsRaw from "$lib/pronouns.json"; +const pronouns = pronounsRaw as PronounsJson; + export const ssr = false; export const load = async () => { @@ -10,6 +13,7 @@ export const load = async () => { return { user, + pronouns: pronouns.autocomplete, }; } catch (e) { throw error((e as APIError).code, (e as APIError).message); diff --git a/frontend/src/routes/pronouns/[...pronouns]/+page.ts b/frontend/src/routes/pronouns/[...pronouns]/+page.ts index 8abd55c..60f252f 100644 --- a/frontend/src/routes/pronouns/[...pronouns]/+page.ts +++ b/frontend/src/routes/pronouns/[...pronouns]/+page.ts @@ -1,9 +1,9 @@ import { error } from "@sveltejs/kit"; import type { PageLoad } from "./$types"; +import type { PronounsJson } from "$lib/api/entities"; -interface Pronouns { - [key: string]: { pronouns: string[]; display?: string }; -} +import pronounsRaw from "$lib/pronouns.json"; +const pronouns = pronounsRaw as PronounsJson; export const load = (async ({ params }) => { const [param, displayText] = params.pronouns.split(","); @@ -24,10 +24,18 @@ export const load = (async ({ params }) => { }; } - const pronouns: Pronouns = (await import("$lib/pronouns.json")).pronouns; - - if (params.pronouns in pronouns) { - const entry = pronouns[params.pronouns]; + if (params.pronouns in pronouns.pages) { + const entry = pronouns.pages[params.pronouns]; + return { + displayText: entry.display || "", + subjective: entry.pronouns[0], + objective: entry.pronouns[1], + possessiveDeterminer: entry.pronouns[2], + possessivePronoun: entry.pronouns[3], + reflexive: entry.pronouns[4], + }; + } else if (params.pronouns in pronouns.autocomplete) { + const entry = pronouns.autocomplete[params.pronouns]; return { displayText: entry.display || "", subjective: entry.pronouns[0],