From ccf7f66a797c9583cf7d4a5a3c08ab6757dc0d70 Mon Sep 17 00:00:00 2001 From: TymanWasTaken Date: Fri, 21 Oct 2022 04:46:38 -0600 Subject: Update PronounDB Plugin (#115) * Add X-PronounDB-Source header, add options to pronoundb * Adapt to defaults fix, better lowercase logic * User popouts :) --- .../components/PronounsAboutComponent.tsx | 18 ++++++++++++ .../pronoundb/components/PronounsChatComponent.tsx | 33 ++++++++++++++++++++++ .../components/PronounsProfileWrapper.tsx | 28 ++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 src/plugins/pronoundb/components/PronounsAboutComponent.tsx create mode 100644 src/plugins/pronoundb/components/PronounsChatComponent.tsx create mode 100644 src/plugins/pronoundb/components/PronounsProfileWrapper.tsx (limited to 'src/plugins/pronoundb/components') diff --git a/src/plugins/pronoundb/components/PronounsAboutComponent.tsx b/src/plugins/pronoundb/components/PronounsAboutComponent.tsx new file mode 100644 index 0000000..0903509 --- /dev/null +++ b/src/plugins/pronoundb/components/PronounsAboutComponent.tsx @@ -0,0 +1,18 @@ +import { Forms, React } from "../../../webpack/common"; + +export default function PronounsAboutComponent() { + return ( + + More Information + + The two pronoun formats are lowercase and capitalized. Example: +
    +
  • Lowercase: they/them
  • +
  • Capitalized: They/Them
  • +
+ Text like "Ask me my pronouns" or "Any pronouns" will always be capitalized.

+ You can also configure whether or not to display pronouns for the current user (since you probably already know them) +
+
+ ); +} diff --git a/src/plugins/pronoundb/components/PronounsChatComponent.tsx b/src/plugins/pronoundb/components/PronounsChatComponent.tsx new file mode 100644 index 0000000..3e4e77f --- /dev/null +++ b/src/plugins/pronoundb/components/PronounsChatComponent.tsx @@ -0,0 +1,33 @@ +import { Message } from "discord-types/general"; +import { fetchPronouns, formatPronouns } from "../utils"; +import { classes, lazyWebpack, useAwaiter } from "../../../utils/misc"; +import { PronounMapping } from "../types"; +import { filters } from "../../../webpack"; +import { UserStore } from "../../../webpack/common"; +import { Settings } from "../../../Vencord"; + +const styles: Record = lazyWebpack(filters.byProps(["timestampInline"])); + +export default function PronounsChatComponent({ message }: { message: Message; }) { + // Don't bother fetching bot or system users + if (message.author.bot || message.author.system) return null; + // Respect showSelf options + if (!Settings.plugins.PronounDB.showSelf && message.author.id === UserStore.getCurrentUser().id) return null; + + const [result, , isPending] = useAwaiter( + () => fetchPronouns(message.author.id), + null, + e => console.error("Fetching pronouns failed: ", e) + ); + + // If the promise completed, the result was not "unspecified", and there is a mapping for the code, then return a span with the pronouns + if (!isPending && result && result !== "unspecified" && PronounMapping[result]) { + return ( + • {formatPronouns(result)} + ); + } + // Otherwise, return null so nothing else is rendered + else return null; +} diff --git a/src/plugins/pronoundb/components/PronounsProfileWrapper.tsx b/src/plugins/pronoundb/components/PronounsProfileWrapper.tsx new file mode 100644 index 0000000..a8f2ff4 --- /dev/null +++ b/src/plugins/pronoundb/components/PronounsProfileWrapper.tsx @@ -0,0 +1,28 @@ +import { UserStore } from "../../../webpack/common"; +import { Settings } from "../../../Vencord"; +import { PronounMapping, UserProfileProps } from "../types"; +import { useAwaiter, classes } from "../../../utils"; +import { fetchPronouns, formatPronouns } from "../utils"; + +export default function PronounsProfileWrapper(props: UserProfileProps, pronounsComponent: JSX.Element) { + // Don't bother fetching bot or system users + if (props.user.bot || props.user.system) return null; + // Respect showSelf options + if (!Settings.plugins.PronounDB.showSelf && props.user.id === UserStore.getCurrentUser().id) return null; + + const [result, , isPending] = useAwaiter( + () => fetchPronouns(props.user.id), + null, + e => console.error("Fetching pronouns failed: ", e) + ); + + // If the promise completed, the result was not "unspecified", and there is a mapping for the code, then return a span with the pronouns + if (!isPending && result && result !== "unspecified" && PronounMapping[result]) { + // First child is the header, second is a div with the actual text + const [, pronounsBodyComponent] = pronounsComponent.props.children as [JSX.Element, JSX.Element]; + pronounsBodyComponent.props.children = formatPronouns(result); + return pronounsComponent; + } + // Otherwise, return null so nothing else is rendered + else return null; +} -- cgit