Fix: user not having icon when id starts with a letter
This commit is contained in:
parent
0a47163f9b
commit
25949b97a7
3 changed files with 15 additions and 3 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { useContext } from "react";
|
import { useContext, useEffect, useState } from "react";
|
||||||
import { FaDiscord, FaGithub, FaTwitter } from "react-icons/fa";
|
import { FaDiscord, FaGithub, FaTwitter } from "react-icons/fa";
|
||||||
import { Link, useLocation, useNavigate } from "react-router-dom";
|
import { Link, useLocation, useNavigate } from "react-router-dom";
|
||||||
import AlertDropdown from "../../alerts/alertDropDown";
|
import AlertDropdown from "../../alerts/alertDropDown";
|
||||||
|
|
@ -27,7 +27,7 @@ export default function Header(): JSX.Element {
|
||||||
const { notificationCenter } = useContext(alertContext);
|
const { notificationCenter } = useContext(alertContext);
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const { logout, autoLogin, isAdmin, userData } = useContext(AuthContext);
|
const { logout, autoLogin, isAdmin, userData } = useContext(AuthContext);
|
||||||
const { stars } = useContext(darkContext);
|
const { stars, gradientIndex } = useContext(darkContext);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -140,7 +140,7 @@ export default function Header(): JSX.Element {
|
||||||
className={
|
className={
|
||||||
"h-7 w-7 rounded-full focus-visible:outline-0 " +
|
"h-7 w-7 rounded-full focus-visible:outline-0 " +
|
||||||
gradients[
|
gradients[
|
||||||
parseInt(userData?.id ?? "", 10) % gradients.length
|
gradientIndex
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ const initialValue = {
|
||||||
setDark: () => {},
|
setDark: () => {},
|
||||||
stars: 0,
|
stars: 0,
|
||||||
setStars: (stars) => 0,
|
setStars: (stars) => 0,
|
||||||
|
gradientIndex: 0,
|
||||||
|
setGradientIndex: () => 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const darkContext = createContext<darkContextType>(initialValue);
|
export const darkContext = createContext<darkContextType>(initialValue);
|
||||||
|
|
@ -16,6 +18,7 @@ export function DarkProvider({ children }) {
|
||||||
JSON.parse(window.localStorage.getItem("isDark")!) ?? false
|
JSON.parse(window.localStorage.getItem("isDark")!) ?? false
|
||||||
);
|
);
|
||||||
const [stars, setStars] = useState<number>(0);
|
const [stars, setStars] = useState<number>(0);
|
||||||
|
const [gradientIndex, setGradientIndex] = useState<number>(0);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchStars() {
|
async function fetchStars() {
|
||||||
|
|
@ -23,6 +26,11 @@ export function DarkProvider({ children }) {
|
||||||
setStars(starsCount);
|
setStars(starsCount);
|
||||||
}
|
}
|
||||||
fetchStars();
|
fetchStars();
|
||||||
|
const min = 0;
|
||||||
|
const max = 30;
|
||||||
|
setGradientIndex(
|
||||||
|
Math.floor(Math.random() * (max - min + 1)) + min
|
||||||
|
)
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -41,6 +49,8 @@ export function DarkProvider({ children }) {
|
||||||
stars,
|
stars,
|
||||||
dark,
|
dark,
|
||||||
setDark,
|
setDark,
|
||||||
|
setGradientIndex,
|
||||||
|
gradientIndex,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@ export type darkContextType = {
|
||||||
setDark: (newState: {}) => void;
|
setDark: (newState: {}) => void;
|
||||||
stars: number;
|
stars: number;
|
||||||
setStars: (stars: number) => void;
|
setStars: (stars: number) => void;
|
||||||
|
gradientIndex: number;
|
||||||
|
setGradientIndex: (index: number) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type locationContextType = {
|
export type locationContextType = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue