From 81edc1407071c6c0328f40a1ee487ea0388b9a7e Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sat, 12 Nov 2022 15:09:02 +0100 Subject: fix PronounDB crash with new profile in dms, force start dependencies --- .../pronoundb/components/PronounsChatComponent.tsx | 16 +++++++++++----- .../pronoundb/components/PronounsProfileWrapper.tsx | 20 +++++++++++++++++--- 2 files changed, 28 insertions(+), 8 deletions(-) (limited to 'src/plugins/pronoundb/components') diff --git a/src/plugins/pronoundb/components/PronounsChatComponent.tsx b/src/plugins/pronoundb/components/PronounsChatComponent.tsx index 78cee48..57033cc 100644 --- a/src/plugins/pronoundb/components/PronounsChatComponent.tsx +++ b/src/plugins/pronoundb/components/PronounsChatComponent.tsx @@ -27,12 +27,18 @@ import { PronounMapping } from "../types"; const styles: Record = lazyWebpack(filters.byProps("timestampInline")); -export default function PronounsChatComponent({ message }: { message: Message; }) { +export default function PronounsChatComponentWrapper({ message }: { message: Message; }) { // Don't bother fetching bot or system users - if (message.author.bot || message.author.system) return null; + 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; + if (!Settings.plugins.PronounDB.showSelf && message.author.id === UserStore.getCurrentUser().id) + return null; + return ; +} + +function PronounsChatComponent({ message }: { message: Message; }) { const [result, , isPending] = useAwaiter( () => fetchPronouns(message.author.id), null, @@ -47,6 +53,6 @@ export default function PronounsChatComponent({ message }: { message: Message; } >• {formatPronouns(result)} ); } - // Otherwise, return null so nothing else is rendered - else return null; + + return null; } diff --git a/src/plugins/pronoundb/components/PronounsProfileWrapper.tsx b/src/plugins/pronoundb/components/PronounsProfileWrapper.tsx index 139fb8a..b39f4ed 100644 --- a/src/plugins/pronoundb/components/PronounsProfileWrapper.tsx +++ b/src/plugins/pronoundb/components/PronounsProfileWrapper.tsx @@ -30,8 +30,22 @@ export default function PronounsProfileWrapper(PronounsComponent: React.ElementT if (!Settings.plugins.PronounDB.showSelf && user.id === UserStore.getCurrentUser().id) return null; + return ; +} + +function ProfilePronouns( + { userId, Component, leProps }: { + userId: string; + Component: React.ElementType; + leProps: UserProfilePronounsProps; + } +) { const [result, , isPending] = useAwaiter( - () => fetchPronouns(user.id), + () => fetchPronouns(userId), null, e => console.error("Fetching pronouns failed: ", e) ); @@ -39,8 +53,8 @@ export default function PronounsProfileWrapper(PronounsComponent: React.ElementT // If the promise completed, the result was not "unspecified", and there is a mapping for the code, then render if (!isPending && result && result !== "unspecified" && PronounMapping[result]) { // First child is the header, second is a div with the actual text - props.currentPronouns ||= formatPronouns(result); - return ; + leProps.currentPronouns ||= formatPronouns(result); + return ; } return null; -- cgit