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

View File

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

View File

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

View File

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