2023-12-07 23:11:51 +01:00
|
|
|
import { createContext, useEffect, useState } from "react";
|
|
|
|
import AnythingLLM from "./media/logo/anything-llm.png";
|
2024-05-23 23:14:53 +02:00
|
|
|
import DefaultLoginLogo from "./media/illustrations/login-logo.svg";
|
2023-12-07 23:11:51 +01:00
|
|
|
import System from "./models/system";
|
|
|
|
|
|
|
|
export const LogoContext = createContext();
|
|
|
|
|
|
|
|
export function LogoProvider({ children }) {
|
|
|
|
const [logo, setLogo] = useState("");
|
2024-05-23 23:14:53 +02:00
|
|
|
const [loginLogo, setLoginLogo] = useState("");
|
|
|
|
const [isCustomLogo, setIsCustomLogo] = useState(false);
|
2023-12-07 23:11:51 +01:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
async function fetchInstanceLogo() {
|
|
|
|
try {
|
2024-05-23 23:14:53 +02:00
|
|
|
const { isCustomLogo, logoURL } = await System.fetchLogo();
|
|
|
|
if (logoURL) {
|
|
|
|
setLogo(logoURL);
|
|
|
|
setLoginLogo(isCustomLogo ? logoURL : DefaultLoginLogo);
|
|
|
|
setIsCustomLogo(isCustomLogo);
|
|
|
|
} else {
|
|
|
|
setLogo(AnythingLLM);
|
|
|
|
setLoginLogo(DefaultLoginLogo);
|
|
|
|
setIsCustomLogo(false);
|
|
|
|
}
|
2023-12-07 23:11:51 +01:00
|
|
|
} catch (err) {
|
|
|
|
setLogo(AnythingLLM);
|
2024-05-23 23:14:53 +02:00
|
|
|
setLoginLogo(DefaultLoginLogo);
|
|
|
|
setIsCustomLogo(false);
|
2023-12-07 23:11:51 +01:00
|
|
|
console.error("Failed to fetch logo:", err);
|
|
|
|
}
|
|
|
|
}
|
2024-05-23 23:14:53 +02:00
|
|
|
|
2023-12-07 23:11:51 +01:00
|
|
|
fetchInstanceLogo();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
2024-05-23 23:14:53 +02:00
|
|
|
<LogoContext.Provider value={{ logo, setLogo, loginLogo, isCustomLogo }}>
|
2023-12-07 23:11:51 +01:00
|
|
|
{children}
|
|
|
|
</LogoContext.Provider>
|
|
|
|
);
|
|
|
|
}
|