diff options
author | TymanWasTaken <tbeckman530@gmail.com> | 2022-10-21 04:46:38 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-21 12:46:38 +0200 |
commit | ccf7f66a797c9583cf7d4a5a3c08ab6757dc0d70 (patch) | |
tree | 43ee82a83fdce323ce3f71a2d7ba7adc80df2dba /src/plugins/pronoundb/components | |
parent | d8afde2b4d03c1d46795f18db8256cd095ae1e85 (diff) | |
download | Vencord-ccf7f66a797c9583cf7d4a5a3c08ab6757dc0d70.tar.gz Vencord-ccf7f66a797c9583cf7d4a5a3c08ab6757dc0d70.tar.bz2 Vencord-ccf7f66a797c9583cf7d4a5a3c08ab6757dc0d70.zip |
Update PronounDB Plugin (#115)
* Add X-PronounDB-Source header, add options to pronoundb
* Adapt to defaults fix, better lowercase logic
* User popouts :)
Diffstat (limited to 'src/plugins/pronoundb/components')
3 files changed, 79 insertions, 0 deletions
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 ( + <React.Fragment> + <Forms.FormTitle tag="h3">More Information</Forms.FormTitle> + <Forms.FormText> + The two pronoun formats are lowercase and capitalized. Example: + <ul> + <li>Lowercase: they/them</li> + <li>Capitalized: They/Them</li> + </ul> + Text like "Ask me my pronouns" or "Any pronouns" will always be capitalized. <br /><br /> + You can also configure whether or not to display pronouns for the current user (since you probably already know them) + </Forms.FormText> + </React.Fragment> + ); +} 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<string, string> = 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 ( + <span + className={classes(styles.timestampInline, styles.timestamp)} + >• {formatPronouns(result)}</span> + ); + } + // 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; +} |