mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-30 00:29:46 +08:00
5870a6097a
* Chore/unit test (#538) * chore: add unit test * chore: add github action for unit test * feat: init firebase * chore: add development secrets * fix: rename auth -> data-services * feat: update blocksuite 0.3.0-alpha.4 (#543) * feat: add requests * feat: optimize swr cache * feat: add Authorization * feat: add confirm-invitation page * feat: add account sdk api and proxy * docs: update contributing (#550) * docs: update contributing * Update CONTRIBUTING.md * Update CONTRIBUTING.md Co-authored-by: ShortCipher5 <me@shortcipher.me> * feat: update api * feat: remove babelrc setting * feat: add create workspace ui * feat: choose workspaces * feat: login modal * feat: authorization api * feat: login status * fix: remove unused variables * feat: login button * fix: lint * fix: workspace id * fix: i18n type error Co-authored-by: MingLiang Wang <mingliangwang0o0@gmail.com> Co-authored-by: ShortCipher5 <me@shortcipher.me>
109 lines
2.8 KiB
TypeScript
109 lines
2.8 KiB
TypeScript
import { createContext, useContext, useState } from 'react';
|
|
import type { PropsWithChildren } from 'react';
|
|
import ShortcutsModal from '@/components/shortcuts-modal';
|
|
import ContactModal from '@/components/contact-modal';
|
|
import QuickSearch from '@/components/quick-search';
|
|
import { ImportModal } from '@/components/import';
|
|
import { LoginModal } from '@/components/login-modal';
|
|
|
|
type ModalContextValue = {
|
|
triggerShortcutsModal: () => void;
|
|
triggerContactModal: () => void;
|
|
triggerQuickSearchModal: (visible?: boolean) => void;
|
|
triggerImportModal: () => void;
|
|
triggerLoginModal: () => void;
|
|
};
|
|
type ModalContextProps = PropsWithChildren<{}>;
|
|
type ModalMap = {
|
|
contact: boolean;
|
|
shortcuts: boolean;
|
|
quickSearch: boolean;
|
|
import: boolean;
|
|
login: boolean;
|
|
};
|
|
|
|
export const ModalContext = createContext<ModalContextValue>({
|
|
triggerShortcutsModal: () => {},
|
|
triggerContactModal: () => {},
|
|
triggerQuickSearchModal: (visible?) => {},
|
|
triggerImportModal: () => {},
|
|
triggerLoginModal: () => {},
|
|
});
|
|
|
|
export const useModal = () => useContext(ModalContext);
|
|
|
|
export const ModalProvider = ({
|
|
children,
|
|
}: PropsWithChildren<ModalContextProps>) => {
|
|
const [modalMap, setModalMap] = useState<ModalMap>({
|
|
contact: false,
|
|
shortcuts: false,
|
|
quickSearch: false,
|
|
import: false,
|
|
login: false,
|
|
});
|
|
|
|
const triggerHandler = (key: keyof ModalMap, visible?: boolean) => {
|
|
setModalMap({
|
|
...modalMap,
|
|
[key]: visible ?? !modalMap[key],
|
|
});
|
|
};
|
|
|
|
return (
|
|
<ModalContext.Provider
|
|
value={{
|
|
triggerShortcutsModal: () => {
|
|
triggerHandler('shortcuts');
|
|
},
|
|
triggerContactModal: () => {
|
|
triggerHandler('contact');
|
|
},
|
|
triggerQuickSearchModal: (visible?) => {
|
|
triggerHandler('quickSearch', visible);
|
|
},
|
|
triggerImportModal: () => {
|
|
triggerHandler('import');
|
|
},
|
|
triggerLoginModal: () => {
|
|
triggerHandler('login');
|
|
},
|
|
}}
|
|
>
|
|
<ContactModal
|
|
open={modalMap.contact}
|
|
onClose={() => {
|
|
triggerHandler('contact', false);
|
|
}}
|
|
></ContactModal>
|
|
<ShortcutsModal
|
|
open={modalMap.shortcuts}
|
|
onClose={() => {
|
|
triggerHandler('shortcuts', false);
|
|
}}
|
|
></ShortcutsModal>
|
|
<QuickSearch
|
|
open={modalMap.quickSearch}
|
|
onClose={() => {
|
|
triggerHandler('quickSearch', false);
|
|
}}
|
|
></QuickSearch>
|
|
<ImportModal
|
|
open={modalMap.import}
|
|
onClose={() => {
|
|
triggerHandler('import', false);
|
|
}}
|
|
></ImportModal>
|
|
<LoginModal
|
|
open={modalMap.login}
|
|
onClose={() => {
|
|
triggerHandler('login', false);
|
|
}}
|
|
/>
|
|
{children}
|
|
</ModalContext.Provider>
|
|
);
|
|
};
|
|
|
|
export default ModalProvider;
|