2023-03-22 18:11:54 -05:00
|
|
|
import useCollectionStore from "@/store/collections";
|
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-05-18 13:02:17 -05:00
|
|
|
import useAccountStore from "@/store/account";
|
2023-11-26 04:17:08 -06:00
|
|
|
import useLocalSettingsStore from "@/store/localSettings";
|
2023-02-18 21:32:02 -06:00
|
|
|
|
2023-06-09 17:31:14 -05:00
|
|
|
export default function useInitialData() {
|
2023-05-18 13:02:17 -05:00
|
|
|
const { status, data } = useSession();
|
2023-03-22 18:11:54 -05:00
|
|
|
const { setCollections } = useCollectionStore();
|
|
|
|
const { setTags } = useTagStore();
|
2023-06-14 17:34:54 -05:00
|
|
|
// const { setLinks } = useLinkStore();
|
2023-11-06 07:25:57 -06:00
|
|
|
const { account, setAccount } = useAccountStore();
|
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();
|
2023-11-06 07:25:57 -06:00
|
|
|
if (status === "authenticated") {
|
2023-11-26 04:17:08 -06:00
|
|
|
// Get account info
|
2023-11-06 07:25:57 -06:00
|
|
|
setAccount(data?.user.id as number);
|
|
|
|
}
|
|
|
|
}, [status, data]);
|
|
|
|
|
|
|
|
// Get the rest of the data
|
|
|
|
useEffect(() => {
|
|
|
|
if (account.id && (!process.env.NEXT_PUBLIC_STRIPE || account.username)) {
|
2023-02-18 21:32:02 -06:00
|
|
|
setCollections();
|
2023-02-24 11:32:28 -06:00
|
|
|
setTags();
|
2023-06-14 17:34:54 -05:00
|
|
|
// setLinks();
|
2023-02-18 21:32:02 -06:00
|
|
|
}
|
2023-11-06 07:25:57 -06:00
|
|
|
}, [account]);
|
2023-02-18 21:32:02 -06:00
|
|
|
}
|