ProfileCollectionsAPI: Apply Some Misc Fixes
This commit is contained in:
parent
19b6d56963
commit
487384c97e
7 changed files with 9 additions and 24 deletions
|
|
@ -268,7 +268,7 @@ export const startPlugin = traceFunction("startPlugin", function startPlugin(p:
|
|||
}
|
||||
if (audioProcessor) addAudioProcessor(name, audioProcessor);
|
||||
if (userAreaButton) addUserAreaButton(name, userAreaButton.render, userAreaButton.priority);
|
||||
if (renderProfileCollection) addProfileCollection(name, renderProfileCollection, userAreaButton?.priority);
|
||||
if (renderProfileCollection) addProfileCollection(name, renderProfileCollection);
|
||||
|
||||
return true;
|
||||
}, p => `startPlugin ${p.name}`);
|
||||
|
|
|
|||
|
|
@ -7,22 +7,14 @@
|
|||
import ErrorBoundary from "@components/ErrorBoundary";
|
||||
import { Logger } from "@utils/Logger";
|
||||
import { useEffect, useState } from "@webpack/common";
|
||||
import type { JSX } from "react";
|
||||
import type { JSX, ReactNode } from "react";
|
||||
|
||||
const logger = new Logger("ProfileCollectionAPI");
|
||||
|
||||
export type ProfileCollectionFactory = Function;
|
||||
|
||||
export interface ProfileCollectionData {
|
||||
/** Function that renders the collection component, receives the full profile props */
|
||||
render: ProfileCollectionFactory;
|
||||
/** Higher priority collections appear first in the list. Default: 0 */
|
||||
priority?: number;
|
||||
}
|
||||
export type ProfileCollectionFactory = (props: any) => ReactNode | null;
|
||||
|
||||
interface CollectionEntry {
|
||||
render: ProfileCollectionFactory;
|
||||
priority: number;
|
||||
}
|
||||
|
||||
const profileCollections = new Map<string, CollectionEntry>();
|
||||
|
|
@ -41,7 +33,7 @@ const profileCollectionListeners = new Set<() => void>();
|
|||
* ));
|
||||
*/
|
||||
export function addProfileCollection(id: string, render: ProfileCollectionFactory, priority = 0) {
|
||||
profileCollections.set(id, { render, priority });
|
||||
profileCollections.set(id, { render });
|
||||
profileCollectionListeners.forEach(listener => listener());
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +57,6 @@ function ProfileCollections({ props }: { props: any; }) {
|
|||
}, []);
|
||||
|
||||
return Array.from(profileCollections)
|
||||
.sort(([, a], [, b]) => b.priority - a.priority)
|
||||
.map(([id, { render: Collection }]) => (
|
||||
<ErrorBoundary noop key={id} onError={e => logger.error(`Failed to render profile collection: ${id}`, e.error)}>
|
||||
{Collection({ ...props, user: props.user ?? props.currentUser })}
|
||||
|
|
|
|||
|
|
@ -59,14 +59,14 @@ export default definePlugin({
|
|||
}
|
||||
}
|
||||
],
|
||||
renderProfileCollection: ErrorBoundary.wrap((props: { user: User; displayProfile?: any; }) => {
|
||||
renderProfileCollection: (props: { user: User; displayProfile?: any; }) => {
|
||||
return (
|
||||
<ProfilePopoutComponent
|
||||
{...props}
|
||||
id={props.user.id}
|
||||
/>
|
||||
);
|
||||
}, { noop: true }),
|
||||
},
|
||||
renderProfileRepositoriesTab: ErrorBoundary.wrap((props: { user: User; displayProfile?: any; }) => {
|
||||
return (
|
||||
<ProfileTabComponent
|
||||
|
|
|
|||
|
|
@ -56,6 +56,6 @@ export default definePlugin({
|
|||
useAuthorizationStore.persist.rehydrate();
|
||||
},
|
||||
|
||||
renderProfileCollection: ErrorBoundary.wrap(ProfileSongs, { noop: true }),
|
||||
renderProfileCollection: ProfileSongs,
|
||||
renderWidgetSongs: ErrorBoundary.wrap(WidgetSongs, { noop: true }),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import "./style.css";
|
||||
|
||||
import { isPluginEnabled } from "@api/PluginManager";
|
||||
import { definePluginSettings } from "@api/Settings";
|
||||
import { UserAreaButton, UserAreaRenderProps } from "@api/UserArea";
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
[class*="panels"] [class*="avatarWrapper"] {
|
||||
min-width: 0;
|
||||
}
|
||||
|
|
@ -19,7 +19,6 @@
|
|||
import "./style.css";
|
||||
|
||||
import { NavContextMenuPatchCallback } from "@api/ContextMenu";
|
||||
import ErrorBoundary from "@components/ErrorBoundary";
|
||||
import { OpenExternalIcon } from "@components/Icons";
|
||||
import { Paragraph } from "@components/Paragraph";
|
||||
import { Span } from "@components/Span";
|
||||
|
|
@ -136,7 +135,7 @@ export default definePlugin({
|
|||
}, 4000);
|
||||
},
|
||||
|
||||
renderProfileCollection: ErrorBoundary.wrap(({ user, isSideBar = false }: { user: User; isSideBar?: boolean; }) => {
|
||||
renderProfileCollection: ({ user, isSideBar = false }: { user: User; isSideBar?: boolean; }) => {
|
||||
const [reviewData] = useAwaiter(() => getReviews(user.id, { limit: 4 }), { deps: [user.id], fallbackValue: null });
|
||||
|
||||
// Discord are masters at using a crap ton of html elements and css classes to create a simple ui that could have
|
||||
|
|
@ -193,5 +192,5 @@ export default definePlugin({
|
|||
return isSideBar
|
||||
? <div className={DMSideBarClasses.widgetPreviews}>{reviewsSection}</div>
|
||||
: reviewsSection;
|
||||
}, { noop: true })
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue