fix: make PronounLink reactive, fixes wrong pronouns showing up

This commit is contained in:
Sam 2023-03-21 15:06:55 +01:00
parent 938005cd9f
commit cafebec8ec
No known key found for this signature in database
GPG key ID: B4EF20DDE721CAA1

View file

@ -4,18 +4,25 @@
export let pronouns: Pronoun; export let pronouns: Pronoun;
let pronounText: string; let pronounText: string;
$: pronounText = updatePronouns(pronouns);
const updatePronouns = (pronouns: Pronoun) => {
if (pronouns.display_text) { if (pronouns.display_text) {
pronounText = pronouns.display_text; return pronouns.display_text;
} else { } else {
const split = pronouns.pronouns.split("/"); const split = pronouns.pronouns.split("/");
if (split.length < 2) pronounText = split.join("/"); if (split.length < 2) return split.join("/");
else pronounText = split.slice(0, 2).join("/"); else return split.slice(0, 2).join("/");
} }
};
const link = pronouns.display_text let link: string;
let shouldLink: boolean;
$: link = pronouns.display_text
? `${pronouns.pronouns},${pronouns.display_text}` ? `${pronouns.pronouns},${pronouns.display_text}`
: pronouns.pronouns; : pronouns.pronouns;
const shouldLink = pronouns.pronouns.split("/").length === 5; $: shouldLink = pronouns.pronouns.split("/").length === 5;
</script> </script>
{#if shouldLink} {#if shouldLink}