From f7311ec063da9b57b73c53192a00422e3e7245bb Mon Sep 17 00:00:00 2001 From: Sqaaakoi Date: Sat, 13 Jul 2024 08:12:30 +1200 Subject: [PATCH] SimplifiedProfileNotes: Fix for update + bot profiles + icon is now hidden while loading + fix clearing note will hide box on next open as if empty --- src/plugins/simplifiedProfileNotes/index.tsx | 23 ++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/plugins/simplifiedProfileNotes/index.tsx b/src/plugins/simplifiedProfileNotes/index.tsx index 4780c0dd3..2d64baf50 100644 --- a/src/plugins/simplifiedProfileNotes/index.tsx +++ b/src/plugins/simplifiedProfileNotes/index.tsx @@ -28,6 +28,7 @@ const settings = definePluginSettings({ type NoteHook = { visible: boolean; + loading: boolean; autoFocus: boolean; note: string; activate: () => void; @@ -40,10 +41,13 @@ type NotesSectionProps = { function useNoteBox(userId: string): NoteHook { const { note, loading } = useNote(userId); - const [forced, setForced] = useState(!settings.store.hideWhenEmpty); + const hasNote = !loading && (typeof note === "string" && note?.length > 0); + const [forced, setForced] = useState(!settings.store.hideWhenEmpty || hasNote); const [autoFocus, setAutoFocus] = useState(false); + if (hasNote && !forced) setForced(true); return { - visible: forced || (!loading && note !== undefined), + visible: forced || hasNote, + loading, autoFocus, note, activate() { @@ -81,7 +85,8 @@ export default definePlugin({ patches: [ { // Popout - find: /\.BITE_SIZE,onOpenProfile:\i,usernameIcon:/, + find: /\.BITE_SIZE,onOpenProfile:\i,/, + all: true, replacement: { match: /currentUser:\i,guild:\i,onOpenProfile:.+?}\)(?=])(?<=user:(\i),bio:null==(\i)\?.+?)/, replace: "$&,$self.NotesSection({ user: $1, ...vencordNotesHook })" @@ -91,8 +96,8 @@ export default definePlugin({ // DM Sidebar find: /getRelationshipType.{0,800}\.Overlay.{0,200}Messages\.USER_POPOUT_ABOUT_ME/, replacement: { - match: /(\(0,.{0,50}Messages\.USER_PROFILE_MEMBER_SINCE.{0,100}userId:(\i)\.id}\)\}\))]/, - replace: "$1,$self.NotesSection({ headingColor: 'header-primary', user: $2, ...vencordNotesHook })]" + match: /(\(0,.{0,50}?Messages\.USER_PROFILE_MEMBER_SINCE.{0,100}?userId:(\i)\.id}\)\}\))/, + replace: "$1,$self.NotesSection({ headingColor: 'header-primary', user: $2, ...vencordNotesHook })" } } ].map(p => ({ @@ -100,12 +105,12 @@ export default definePlugin({ group: true, replacement: [ { - match: /getRelationshipType\((\i.id)\)\)/, - replace: "$&,vencordNotesHook=$self.useNoteBox($1)" + match: /hidePersonalInformation\)/, + replace: "$&,vencordNotesHook=$self.useNoteBox(arguments[0].user.id)" }, { - match: /(!\i)(&&\(0,\i\.jsx\)\(\i\.\i,{user:\i,isHovering:\i,onOpenProfile:\(\)=>).{1,20}?\({subsection:\i\.\i\.NOTE}\)/, - replace: "($1&&!vencordNotesHook.visible)$2vencordNotesHook.activate()" + match: /(!\i)(&&\(0,\i\.jsx\)\(\i\.\i,{userId:\i\.id,isHovering:\i,onOpenProfile:)\i/, + replace: "($1&&!vencordNotesHook.visible&&!vencordNotesHook.loading)$2()=>vencordNotesHook.activate()" }, p.replacement ]