mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 01:09:54 +08:00
refactor: improve code
This commit is contained in:
@@ -6,7 +6,7 @@ import './temporary.css';
|
|||||||
import { Logger } from '@toeverything/pathfinder-logger';
|
import { Logger } from '@toeverything/pathfinder-logger';
|
||||||
import '@fontsource/space-mono';
|
import '@fontsource/space-mono';
|
||||||
import '@fontsource/poppins';
|
import '@fontsource/poppins';
|
||||||
import { printBuildInfo } from '../utils/print-build-info';
|
import '../utils/print-build-info';
|
||||||
import ProviderComposer from '@/components/provider-composer';
|
import ProviderComposer from '@/components/provider-composer';
|
||||||
import type { PropsWithChildren, ReactElement, ReactNode } from 'react';
|
import type { PropsWithChildren, ReactElement, ReactNode } from 'react';
|
||||||
import type { NextPage } from 'next';
|
import type { NextPage } from 'next';
|
||||||
@@ -17,6 +17,7 @@ import { useRouter } from 'next/router';
|
|||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { useAppState } from '@/providers/app-state-provider';
|
import { useAppState } from '@/providers/app-state-provider';
|
||||||
import { PageLoading } from '@/components/loading';
|
import { PageLoading } from '@/components/loading';
|
||||||
|
|
||||||
const ThemeProvider = dynamic(() => import('@/providers/themeProvider'), {
|
const ThemeProvider = dynamic(() => import('@/providers/themeProvider'), {
|
||||||
ssr: false,
|
ssr: false,
|
||||||
});
|
});
|
||||||
@@ -34,9 +35,7 @@ type AppPropsWithLayout = AppProps & {
|
|||||||
|
|
||||||
const App = ({ Component, pageProps }: AppPropsWithLayout) => {
|
const App = ({ Component, pageProps }: AppPropsWithLayout) => {
|
||||||
const getLayout = Component.getLayout || (page => page);
|
const getLayout = Component.getLayout || (page => page);
|
||||||
useEffect(() => {
|
|
||||||
printBuildInfo();
|
|
||||||
}, []);
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Logger />
|
<Logger />
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
CLIENT_APP?: boolean;
|
CLIENT_APP?: boolean;
|
||||||
|
__editoVersion?: string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,18 +12,7 @@ type Config = {
|
|||||||
|
|
||||||
const nextConfig = getConfig();
|
const nextConfig = getConfig();
|
||||||
const publicRuntimeConfig: Config = nextConfig.publicRuntimeConfig;
|
const publicRuntimeConfig: Config = nextConfig.publicRuntimeConfig;
|
||||||
const setAffineAppProperties = () => {
|
|
||||||
const input = document.createElement('input');
|
|
||||||
const id = 'editor-version';
|
|
||||||
if (document.getElementById(id)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
input.value = publicRuntimeConfig.EDITOR_VERSION;
|
|
||||||
input.type = 'hidden';
|
|
||||||
input.id = id;
|
|
||||||
input.setAttribute('data-testid', 'editor-version');
|
|
||||||
document.body.appendChild(input);
|
|
||||||
};
|
|
||||||
const printBuildInfo = () => {
|
const printBuildInfo = () => {
|
||||||
console.group('Build info');
|
console.group('Build info');
|
||||||
console.log('Project:', publicRuntimeConfig.PROJECT_NAME);
|
console.log('Project:', publicRuntimeConfig.PROJECT_NAME);
|
||||||
@@ -47,8 +36,14 @@ const printBuildInfo = () => {
|
|||||||
`https://github.com/toeverything/AFFiNE/tree/${publicRuntimeConfig.COMMIT_HASH}`
|
`https://github.com/toeverything/AFFiNE/tree/${publicRuntimeConfig.COMMIT_HASH}`
|
||||||
);
|
);
|
||||||
console.groupEnd();
|
console.groupEnd();
|
||||||
|
|
||||||
setAffineAppProperties();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export { printBuildInfo };
|
function setWindowEditorVersion() {
|
||||||
|
// when it is not SSR
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
window.__editoVersion = publicRuntimeConfig.EDITOR_VERSION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printBuildInfo();
|
||||||
|
setWindowEditorVersion();
|
||||||
|
export {};
|
||||||
|
|||||||
@@ -9,16 +9,16 @@ test.describe('web console', () => {
|
|||||||
// https://playwright.dev/docs/evaluating
|
// https://playwright.dev/docs/evaluating
|
||||||
// https://github.com/microsoft/playwright/issues/13059
|
// https://github.com/microsoft/playwright/issues/13059
|
||||||
// Get the handle to a specific function.
|
// Get the handle to a specific function.
|
||||||
// const getEditoVersionHandle = await page.evaluate(
|
|
||||||
// 'window.__getEditoVersion'
|
|
||||||
// );
|
|
||||||
//Later on, call this function with some arguments.
|
//Later on, call this function with some arguments.
|
||||||
// const msg = await getEditoVersionHandle.evaluate((post, args) => post);
|
// const msg = await getEditoVersionHandle.evaluate((post, args) => post);
|
||||||
// console.log(getEditoVersionHandle);
|
// console.log(getEditoVersionHandle);
|
||||||
const documentEditorVersion = await page.inputValue('input#editor-version');
|
await page.waitForTimeout(500);
|
||||||
|
const editoVersion = await page.evaluate(
|
||||||
|
() => (window as any).__editoVersion
|
||||||
|
);
|
||||||
|
// const documentEditorVersion = await page.inputValue('input#editor-version');
|
||||||
const pkgEditorVersion = pkg.dependencies['@blocksuite/editor'];
|
const pkgEditorVersion = pkg.dependencies['@blocksuite/editor'];
|
||||||
|
|
||||||
expect(documentEditorVersion).toBe(pkgEditorVersion);
|
expect(editoVersion).toBe(pkgEditorVersion);
|
||||||
console.log('pkgEditorVersion', pkgEditorVersion);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user