fix: infinite loading when no workspaces (#1679)
This commit is contained in:
@@ -67,6 +67,10 @@ const App = function App({
|
|||||||
>
|
>
|
||||||
<Head>
|
<Head>
|
||||||
<title>AFFiNE</title>
|
<title>AFFiNE</title>
|
||||||
|
<meta
|
||||||
|
name="viewport"
|
||||||
|
content="initial-scale=1, width=device-width"
|
||||||
|
/>
|
||||||
</Head>
|
</Head>
|
||||||
{getLayout(<Component {...pageProps} />)}
|
{getLayout(<Component {...pageProps} />)}
|
||||||
</ProviderComposer>
|
</ProviderComposer>
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ export default class AppDocument extends Document<{
|
|||||||
/>
|
/>
|
||||||
<link rel="icon" sizes="192x192" href="/chrome-192x192.png" />
|
<link rel="icon" sizes="192x192" href="/chrome-192x192.png" />
|
||||||
<meta name="emotion-insertion-point" content="" />
|
<meta name="emotion-insertion-point" content="" />
|
||||||
<meta name="viewport" content="initial-scale=1, width=device-width" />
|
|
||||||
<meta name="twitter:card" content="summary_large_image" />
|
<meta name="twitter:card" content="summary_large_image" />
|
||||||
<meta name="twitter:url" content="https://app.affine.pro/" />
|
<meta name="twitter:url" content="https://app.affine.pro/" />
|
||||||
<meta
|
<meta
|
||||||
|
|||||||
@@ -49,10 +49,13 @@ const IndexPageInner = () => {
|
|||||||
dispose.dispose();
|
dispose.dispose();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// fixme: should create new workspace
|
||||||
|
jumpToSubPath('ERROR', WorkspaceSubPath.ALL, RouteLogic.REPLACE);
|
||||||
}
|
}
|
||||||
}, [jumpToPage, jumpToSubPath, lastWorkspaceId, router, workspaces]);
|
}, [jumpToPage, jumpToSubPath, lastWorkspaceId, router, workspaces]);
|
||||||
|
|
||||||
return <PageLoading />;
|
return <PageLoading key="IndexPageInfinitePageLoading" />;
|
||||||
};
|
};
|
||||||
|
|
||||||
const IndexPage: NextPage = () => {
|
const IndexPage: NextPage = () => {
|
||||||
|
|||||||
@@ -4,15 +4,23 @@
|
|||||||
import 'fake-indexeddb/auto';
|
import 'fake-indexeddb/auto';
|
||||||
|
|
||||||
import userA from '@affine-test/fixtures/userA.json';
|
import userA from '@affine-test/fixtures/userA.json';
|
||||||
|
import { assertExists } from '@blocksuite/global/utils';
|
||||||
import { Workspace } from '@blocksuite/store';
|
import { Workspace } from '@blocksuite/store';
|
||||||
import { beforeAll, beforeEach, describe, expect, test } from 'vitest';
|
import { beforeAll, beforeEach, describe, expect, test } from 'vitest';
|
||||||
|
|
||||||
import { createWorkspaceApis, createWorkspaceResponseSchema } from '../api';
|
import { createWorkspaceApis, createWorkspaceResponseSchema } from '../api';
|
||||||
import { loginResponseSchema, setLoginStorage } from '../login';
|
import {
|
||||||
|
createAffineAuth,
|
||||||
|
getLoginStorage,
|
||||||
|
loginResponseSchema,
|
||||||
|
setLoginStorage,
|
||||||
|
} from '../login';
|
||||||
|
|
||||||
let workspaceApis: ReturnType<typeof createWorkspaceApis>;
|
let workspaceApis: ReturnType<typeof createWorkspaceApis>;
|
||||||
|
let affineAuth: ReturnType<typeof createAffineAuth>;
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
|
affineAuth = createAffineAuth('http://localhost:3000/');
|
||||||
workspaceApis = createWorkspaceApis('http://localhost:3000/');
|
workspaceApis = createWorkspaceApis('http://localhost:3000/');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -49,6 +57,12 @@ beforeEach(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('api', () => {
|
describe('api', () => {
|
||||||
|
test('refresh token', async () => {
|
||||||
|
const storage = getLoginStorage();
|
||||||
|
assertExists(storage);
|
||||||
|
loginResponseSchema.parse(await affineAuth.refreshToken(storage));
|
||||||
|
});
|
||||||
|
|
||||||
test(
|
test(
|
||||||
'create workspace',
|
'create workspace',
|
||||||
async () => {
|
async () => {
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ declare global {
|
|||||||
var firebaseAuthEmulatorStarted: boolean | undefined;
|
var firebaseAuthEmulatorStarted: boolean | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createAffineAuth() {
|
export function createAffineAuth(prefix = '/') {
|
||||||
let _firebaseAuth: FirebaseAuth | null = null;
|
let _firebaseAuth: FirebaseAuth | null = null;
|
||||||
const getAuth = (): FirebaseAuth | null => {
|
const getAuth = (): FirebaseAuth | null => {
|
||||||
try {
|
try {
|
||||||
@@ -138,7 +138,7 @@ export function createAffineAuth() {
|
|||||||
const response = await signInWithPopup(auth, provider);
|
const response = await signInWithPopup(auth, provider);
|
||||||
const idToken = await response.user.getIdToken();
|
const idToken = await response.user.getIdToken();
|
||||||
logger.debug(idToken);
|
logger.debug(idToken);
|
||||||
return fetch('/api/user/token', {
|
return fetch(prefix + 'api/user/token', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -161,7 +161,7 @@ export function createAffineAuth() {
|
|||||||
refreshToken: async (
|
refreshToken: async (
|
||||||
loginResponse: LoginResponse
|
loginResponse: LoginResponse
|
||||||
): Promise<LoginResponse | null> => {
|
): Promise<LoginResponse | null> => {
|
||||||
return fetch('/api/user/token', {
|
return fetch(prefix + 'api/user/token', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ test.describe('Local first default workspace', () => {
|
|||||||
test('preset workspace name', async ({ page }) => {
|
test('preset workspace name', async ({ page }) => {
|
||||||
await openHomePage(page);
|
await openHomePage(page);
|
||||||
const workspaceName = page.getByTestId('workspace-name');
|
const workspaceName = page.getByTestId('workspace-name');
|
||||||
|
await page.waitForTimeout(1000);
|
||||||
expect(await workspaceName.textContent()).toBe('Demo Workspace');
|
expect(await workspaceName.textContent()).toBe('Demo Workspace');
|
||||||
await assertCurrentWorkspaceFlavour('local', page);
|
await assertCurrentWorkspaceFlavour('local', page);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user