el.xwx.moe/hooks/useInitialData.tsx

30 lines
822 B
TypeScript
Raw Normal View History

2023-02-18 21:32:02 -06:00
import { useEffect } from "react";
import { useSession } from "next-auth/react";
2023-03-22 18:11:54 -05:00
import useTagStore from "@/store/tags";
2023-11-26 04:17:08 -06:00
import useLocalSettingsStore from "@/store/localSettings";
import { useUser } from "./store/users";
2023-02-18 21:32:02 -06:00
export default function useInitialData() {
2023-05-18 13:02:17 -05:00
const { status, data } = useSession();
2024-07-30 13:57:09 -05:00
// const { setCollections } = useCollectionStore();
2023-03-22 18:11:54 -05:00
const { setTags } = useTagStore();
// const { setLinks } = useLinkStore();
const { data: user = [] } = useUser();
2023-11-26 04:17:08 -06:00
const { setSettings } = useLocalSettingsStore();
2023-02-18 21:32:02 -06:00
useEffect(() => {
2023-11-26 04:17:08 -06:00
setSettings();
}, [status, data]);
// Get the rest of the data
useEffect(() => {
if (user.id && (!process.env.NEXT_PUBLIC_STRIPE || user.username)) {
2024-07-30 13:57:09 -05:00
// setCollections();
setTags();
// setLinks();
2023-02-18 21:32:02 -06:00
}
}, [user]);
return status;
2023-02-18 21:32:02 -06:00
}