mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-12 23:56:36 +08:00
refactor(core): use element atom (#4026)
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
import type { ToastOptions } from '@affine/component';
|
||||
import { toast as basicToast } from '@affine/component';
|
||||
import { assertEquals, assertExists } from '@blocksuite/global/utils';
|
||||
import { getCurrentStore } from '@toeverything/infra/atom';
|
||||
|
||||
import { mainContainerAtom } from '../atoms/element';
|
||||
|
||||
export const toast = (message: string, options?: ToastOptions) => {
|
||||
const mainContainer = getCurrentStore().get(mainContainerAtom);
|
||||
const modal = document.querySelector(
|
||||
'[role=presentation]'
|
||||
) as HTMLElement | null;
|
||||
const mainContainer = document.querySelector(
|
||||
'.main-container'
|
||||
) as HTMLElement | null;
|
||||
) as HTMLDivElement | null;
|
||||
assertExists(mainContainer, 'main container should exist');
|
||||
if (modal) {
|
||||
assertEquals(modal.constructor, HTMLDivElement, 'modal should be div');
|
||||
}
|
||||
return basicToast(message, {
|
||||
portal: modal || mainContainer || document.body,
|
||||
...options,
|
||||
|
||||
Reference in New Issue
Block a user