gear-orders/flask/vite/src/UserContext.tsx

33 lines
779 B
TypeScript
Raw Normal View History

import React from "react";
export interface UserContextData {
username?: string;
2026-03-05 17:55:33 +00:00
telegram_photo_url?: string;
mastodon_server?: string;
mastodon_username?: string;
}
const UserContext = React.createContext<UserContextData>({});
export const useUserContext = (): UserContextData => {
return React.useContext(UserContext);
};
export const UserContextProvider: React.FC<{ children: React.ReactNode }> = ({
children,
}) => {
2026-03-05 17:55:33 +00:00
const [userProfile, setUserProfile] = React.useState<UserContextData>({});
React.useEffect(() => {
fetch(`/api/me`)
.then((response) => response.json())
2026-03-05 17:55:33 +00:00
.then((data) => {
setUserProfile(data);
});
}, []);
return (
2026-03-05 17:55:33 +00:00
<UserContext.Provider value={userProfile}>{children}</UserContext.Provider>
);
};