mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-02 02:00:49 +08:00
fix(core): wrong fetch injected to snapshot downloader (#9460)
This commit is contained in:
@@ -206,6 +206,7 @@ const Dialog = ({
|
||||
loading={disabled}
|
||||
disabled={disabled}
|
||||
onClick={handleImportToSelectedWorkspace}
|
||||
data-testid="import-template-to-workspace-btn"
|
||||
>
|
||||
{selectedWorkspaceName &&
|
||||
t['com.affine.import-template.dialog.createDocToWorkspace']({
|
||||
|
||||
@@ -16,11 +16,15 @@ export const Component = () => {
|
||||
const [searchParams] = useSearchParams();
|
||||
const { jumpToIndex } = useNavigateHelper();
|
||||
useEffect(() => {
|
||||
globalDialogService.open('import-template', {
|
||||
const id = globalDialogService.open('import-template', {
|
||||
templateName: searchParams.get('name') ?? '',
|
||||
templateMode: (searchParams.get('mode') as DocMode) ?? 'page',
|
||||
snapshotUrl: searchParams.get('snapshotUrl') ?? '',
|
||||
});
|
||||
|
||||
return () => {
|
||||
globalDialogService.close(id);
|
||||
};
|
||||
}, [globalDialogService, jumpToIndex, searchParams]);
|
||||
// no ui for this route, just open the dialog
|
||||
return null;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { type Framework } from '@toeverything/infra';
|
||||
|
||||
import { FetchService } from '../cloud';
|
||||
import { RawFetchProvider } from '../cloud';
|
||||
import { WorkspacesService } from '../workspace';
|
||||
import { ImportTemplateDialog } from './entities/dialog';
|
||||
import { TemplateDownloader } from './entities/downloader';
|
||||
@@ -16,6 +16,6 @@ export function configureImportTemplateModule(framework: Framework) {
|
||||
.entity(ImportTemplateDialog)
|
||||
.service(TemplateDownloaderService)
|
||||
.entity(TemplateDownloader, [TemplateDownloaderStore])
|
||||
.store(TemplateDownloaderStore, [FetchService])
|
||||
.store(TemplateDownloaderStore, [RawFetchProvider])
|
||||
.service(ImportTemplateService, [WorkspacesService]);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { Store } from '@toeverything/infra';
|
||||
|
||||
import type { FetchService } from '../../cloud';
|
||||
import type { RawFetchProvider } from '../../cloud';
|
||||
|
||||
export class TemplateDownloaderStore extends Store {
|
||||
constructor(private readonly fetchService: FetchService) {
|
||||
constructor(private readonly fetchProvider: RawFetchProvider) {
|
||||
super();
|
||||
}
|
||||
|
||||
async download(snapshotUrl: string) {
|
||||
const response = await this.fetchService.fetch(snapshotUrl, {
|
||||
const response = await this.fetchProvider.fetch(snapshotUrl, {
|
||||
priority: 'high',
|
||||
} as any);
|
||||
const arrayBuffer = await response.arrayBuffer();
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { test } from '@affine-test/kit/playwright';
|
||||
import { createRandomUser, loginUser } from '@affine-test/kit/utils/cloud';
|
||||
import { waitForEditorLoad } from '@affine-test/kit/utils/page-logic';
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
const user = await createRandomUser();
|
||||
await loginUser(page, user);
|
||||
});
|
||||
|
||||
test('import from template should work', async ({ page }) => {
|
||||
await page.goto('https://affine.pro/templates', { waitUntil: 'load' });
|
||||
|
||||
await page.click('.template-list > a:first-child');
|
||||
const importLink = page.getByText('Use this template');
|
||||
|
||||
const href = await importLink.evaluate((el: HTMLElement) => {
|
||||
const a = el.closest('a');
|
||||
if (!a) {
|
||||
throw new Error('Import link not found');
|
||||
}
|
||||
return a.href;
|
||||
});
|
||||
|
||||
const url = new URL(href);
|
||||
|
||||
await page.goto(url.pathname + url.search);
|
||||
|
||||
const btn = page.getByTestId('import-template-to-workspace-btn');
|
||||
|
||||
await btn.isVisible();
|
||||
btn.click();
|
||||
await waitForEditorLoad(page);
|
||||
});
|
||||
Reference in New Issue
Block a user