feat: cleanup fetcher for prepare refactor

This commit is contained in:
DarkSky
2022-12-22 15:09:49 +08:00
committed by DarkSky
parent b4b8a25742
commit b666fd8d0a
16 changed files with 121 additions and 161 deletions
@@ -1,4 +1,4 @@
import { signInWithGoogle, login, setToken } from '@pathfinder/data-services';
import { signInWithGoogle } from '@pathfinder/data-services';
import { styled } from '@/styles';
import { Button } from '@/ui/button';
import { useModal } from '@/providers/global-modal-provider';
@@ -10,13 +10,7 @@ export const GoogleLoginButton = () => {
<StyledGoogleButton
onClick={() => {
signInWithGoogle()
.then(async user => {
const idToken = await user.user.getIdToken();
const token = await login({ token: idToken, type: 'Google' });
setToken({
accessToken: token.token,
refreshToken: token.refresh,
});
.then(async => {
triggerLoginModal();
})
.catch(error => {
@@ -94,7 +94,7 @@ export const AppStateProvider = ({ children }: { children?: ReactNode }) => {
const editor = createEditorHandler?.(currentPage) || null;
if (editor) {
const pageMeta = currentWorkspace?.meta.pageMetas.find(
const pageMeta = currentWorkspace.meta.pageMetas.find(
p => p.id === currentPage.pageId
);
if (pageMeta?.mode) {
@@ -133,13 +133,13 @@ export const AppStateProvider = ({ children }: { children?: ReactNode }) => {
const callback = async (user: AccessTokenMessage | null) => {
const workspacesMeta = user ? await getWorkspaces() : [];
const workspacesList = await Promise.all(
workspacesMeta?.map(async ({ id }) => {
workspacesMeta.map(async ({ id }) => {
const workspace = (await loadWorkspaceHandler?.(id)) || null;
return { id, workspace };
})
);
let workspaces: Record<string, Workspace | null> = {};
const workspaces: Record<string, Workspace | null> = {};
workspacesList.forEach(({ id, workspace }) => {
workspaces[id] = workspace;