mirror of
https://github.com/Equicord/Equicord.git
synced 2025-02-20 15:18:50 -05:00
IrcColors: Fix causing react errors sometimes
This commit is contained in:
parent
414539f45e
commit
1eff1a02bd
1 changed files with 3 additions and 9 deletions
|
@ -23,11 +23,11 @@ import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { useMemo } from "@webpack/common";
|
import { useMemo } from "@webpack/common";
|
||||||
|
|
||||||
// Calculate a CSS color string based on the user ID
|
// Calculate a CSS color string based on the user ID
|
||||||
function calculateNameColorForUser(id: string) {
|
function calculateNameColorForUser(id?: string) {
|
||||||
const { lightness } = settings.use(["lightness"]);
|
const { lightness } = settings.use(["lightness"]);
|
||||||
const idHash = useMemo(() => h64(id), [id]);
|
const idHash = useMemo(() => id ? h64(id) : null, [id]);
|
||||||
|
|
||||||
return `hsl(${idHash % 360n}, 100%, ${lightness}%)`;
|
return idHash && `hsl(${idHash % 360n}, 100%, ${lightness}%)`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const settings = definePluginSettings({
|
const settings = definePluginSettings({
|
||||||
|
@ -70,16 +70,10 @@ export default definePlugin({
|
||||||
|
|
||||||
calculateNameColorForMessageContext(context: any) {
|
calculateNameColorForMessageContext(context: any) {
|
||||||
const id = context?.message?.author?.id;
|
const id = context?.message?.author?.id;
|
||||||
if (id == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return calculateNameColorForUser(id);
|
return calculateNameColorForUser(id);
|
||||||
},
|
},
|
||||||
calculateNameColorForListContext(context: any) {
|
calculateNameColorForListContext(context: any) {
|
||||||
const id = context?.user?.id;
|
const id = context?.user?.id;
|
||||||
if (id == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return calculateNameColorForUser(id);
|
return calculateNameColorForUser(id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue