Add links to items

This commit is contained in:
Nicolas Mowen 2024-04-28 15:42:07 -06:00
parent 7e98d8c687
commit e55d13f377
4 changed files with 38 additions and 11 deletions

View File

@ -43,7 +43,13 @@ export default function Statusbar() {
useEffect(() => { useEffect(() => {
clearMessages("stats"); clearMessages("stats");
potentialProblems.forEach((problem) => { potentialProblems.forEach((problem) => {
addMessage("stats", problem.text, problem.color); addMessage(
"stats",
problem.text,
problem.color,
undefined,
problem.relevantLink,
);
}); });
}, [potentialProblems, addMessage, clearMessages]); }, [potentialProblems, addMessage, clearMessages]);
@ -110,14 +116,25 @@ export default function Statusbar() {
) : ( ) : (
Object.entries(messages).map(([key, messageArray]) => ( Object.entries(messages).map(([key, messageArray]) => (
<div key={key} className="h-full flex items-center gap-2"> <div key={key} className="h-full flex items-center gap-2">
{messageArray.map(({ id, text, color }: StatusMessage) => ( {messageArray.map(({ id, text, color, link }: StatusMessage) => {
<div key={id} className="flex items-center text-sm gap-2"> const message = (
<IoIosWarning <div
className={`size-5 ${color || "text-danger"}`} key={id}
/> className={`flex items-center text-sm gap-2 ${link ? "hover:underline cursor-pointer" : ""}`}
{text} >
</div> <IoIosWarning
))} className={`size-5 ${color || "text-danger"}`}
/>
{text}
</div>
);
if (link) {
return <a href={link}>{message}</a>;
} else {
return message;
}
})}
</div> </div>
)) ))
)} )}

View File

@ -10,6 +10,7 @@ export type StatusMessage = {
id: string; id: string;
text: string; text: string;
color?: string; color?: string;
link?: string;
}; };
export type StatusMessagesState = { export type StatusMessagesState = {
@ -27,6 +28,7 @@ type StatusBarMessagesContextValue = {
message: string, message: string,
color?: string, color?: string,
messageId?: string, messageId?: string,
link?: string,
) => string; ) => string;
removeMessage: (key: string, messageId: string) => void; removeMessage: (key: string, messageId: string) => void;
clearMessages: (key: string) => void; clearMessages: (key: string) => void;
@ -43,14 +45,20 @@ export function StatusBarMessagesProvider({
const messages = useMemo(() => messagesState, [messagesState]); const messages = useMemo(() => messagesState, [messagesState]);
const addMessage = useCallback( const addMessage = useCallback(
(key: string, message: string, color?: string, messageId?: string) => { (
key: string,
message: string,
color?: string,
messageId?: string,
link?: string,
) => {
const id = messageId || Date.now().toString(); const id = messageId || Date.now().toString();
const msgColor = color || "text-danger"; const msgColor = color || "text-danger";
setMessagesState((prevMessages) => ({ setMessagesState((prevMessages) => ({
...prevMessages, ...prevMessages,
[key]: [ [key]: [
...(prevMessages[key] || []), ...(prevMessages[key] || []),
{ id, text: message, color: msgColor }, { id, text: message, color: msgColor, link },
], ],
})); }));
return id; return id;

View File

@ -53,6 +53,7 @@ export default function useStats(stats: FrigateStats | undefined) {
problems.push({ problems.push({
text: `${capitalizeFirstLetter(name.replaceAll("_", " "))} is offline`, text: `${capitalizeFirstLetter(name.replaceAll("_", " "))} is offline`,
color: "text-danger", color: "text-danger",
relevantLink: "logs",
}); });
} }
}); });

View File

@ -62,6 +62,7 @@ export type StorageStats = {
export type PotentialProblem = { export type PotentialProblem = {
text: string; text: string;
color: string; color: string;
relevantLink?: string;
}; };
export type Vainfo = { export type Vainfo = {