Skip to content

Commit

Permalink
refactor(core): desktop project struct
Browse files Browse the repository at this point in the history
  • Loading branch information
EYHN committed Sep 20, 2024
1 parent e3e15c6 commit 7fc207d
Show file tree
Hide file tree
Showing 58 changed files with 672 additions and 491 deletions.
6 changes: 0 additions & 6 deletions packages/frontend/apps/electron/renderer/app.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { AffineContext } from '@affine/component/context';
import { GlobalLoading } from '@affine/component/global-loading';
import { AppFallback } from '@affine/core/components/affine/app-container';
import { WindowsAppControls } from '@affine/core/components/pure/header/windows-app-controls';
import { Telemetry } from '@affine/core/components/telemetry';
import { router } from '@affine/core/desktop/router';
import { configureCommonModules } from '@affine/core/modules';
import { configureAppTabsHeaderModule } from '@affine/core/modules/app-tabs-header';
import { configureElectronStateStorageImpls } from '@affine/core/modules/storage';
import { CustomThemeModifier } from '@affine/core/modules/theme-editor';
import { configureSqliteUserspaceStorageProvider } from '@affine/core/modules/userspace';
import { configureDesktopWorkbenchModule } from '@affine/core/modules/workbench';
import {
Expand Down Expand Up @@ -85,9 +82,6 @@ export function App() {
<FrameworkRoot framework={frameworkProvider}>
<CacheProvider value={cache}>
<AffineContext store={getCurrentStore()}>
<Telemetry />
<CustomThemeModifier />
<GlobalLoading />
<RouterProvider
fallbackElement={<AppFallback />}
router={router}
Expand Down
2 changes: 0 additions & 2 deletions packages/frontend/apps/mobile/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AffineContext } from '@affine/component/context';
import { AppFallback } from '@affine/core/components/affine/app-container';
import { Telemetry } from '@affine/core/components/telemetry';
import { configureMobileModules } from '@affine/core/mobile/modules';
import { router } from '@affine/core/mobile/router';
import { configureCommonModules } from '@affine/core/modules';
Expand Down Expand Up @@ -59,7 +58,6 @@ export function App() {
<Suspense>
<FrameworkRoot framework={frameworkProvider}>
<AffineContext store={getCurrentStore()}>
<Telemetry />
<RouterProvider
fallbackElement={<AppFallback />}
router={router}
Expand Down
6 changes: 0 additions & 6 deletions packages/frontend/apps/web/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { AffineContext } from '@affine/component/context';
import { GlobalLoading } from '@affine/component/global-loading';
import { AppFallback } from '@affine/core/components/affine/app-container';
import { Telemetry } from '@affine/core/components/telemetry';
import { router } from '@affine/core/desktop/router';
import { configureCommonModules } from '@affine/core/modules';
import { configureLocalStorageStateStorageImpls } from '@affine/core/modules/storage';
import { CustomThemeModifier } from '@affine/core/modules/theme-editor';
import { configureIndexedDBUserspaceStorageProvider } from '@affine/core/modules/userspace';
import { configureBrowserWorkbenchModule } from '@affine/core/modules/workbench';
import {
Expand Down Expand Up @@ -64,9 +61,6 @@ export function App() {
<FrameworkRoot framework={frameworkProvider}>
<CacheProvider value={cache}>
<AffineContext store={getCurrentStore()}>
<Telemetry />
<CustomThemeModifier />
<GlobalLoading />
<RouterProvider
fallbackElement={<AppFallback key="RouterFallback" />}
router={router}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,5 @@
import { useAtomValue } from 'jotai';
import type { ReactNode } from 'react';
import { useEffect, useState } from 'react';

import { Loading } from '../../ui/loading';
import * as styles from './index.css';
import { globalLoadingEventsAtom } from './index.jotai';

export {
type GlobalLoadingEvent,
pushGlobalLoadingEventAtom,
resolveGlobalLoadingEventAtom,
} from './index.jotai';

export function GlobalLoading(): ReactNode {
const globalLoadingEvents = useAtomValue(globalLoadingEventsAtom);
const [loading, setLoading] = useState(false);

useEffect(() => {
if (globalLoadingEvents.length) {
setLoading(true);
} else {
setLoading(false);
}
}, [globalLoadingEvents]);

if (!globalLoadingEvents.length) {
return null;
}
return (
<div className={styles.globalLoadingWrapperStyle} data-loading={loading}>
<Loading size={20} />
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from '@affine/component/setting-components';
import { Avatar } from '@affine/component/ui/avatar';
import { Button } from '@affine/component/ui/button';
import { useSignOut } from '@affine/core/components/hooks/affine/use-sign-out';
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
import { useCatchEventCallback } from '@affine/core/components/hooks/use-catch-event-hook';
import { SubscriptionPlan } from '@affine/graphql';
Expand All @@ -22,11 +23,7 @@ import type { FC } from 'react';
import { useCallback, useEffect, useState } from 'react';

import { AuthService, ServerConfigService } from '../../../../modules/cloud';
import {
authAtom,
openSettingModalAtom,
openSignOutModalAtom,
} from '../../../atoms';
import { authAtom, openSettingModalAtom } from '../../../atoms';
import { Upload } from '../../../pure/file-upload';
import { AIUsagePanel } from './ai-usage-panel';
import { StorageProgress } from './storage-progress';
Expand Down Expand Up @@ -189,7 +186,7 @@ export const AccountSetting: FC = () => {
}, [session]);
const account = useEnsureLiveData(session.account$);
const setAuthModal = useSetAtom(authAtom);
const setSignOutModal = useSetAtom(openSignOutModalAtom);
const openSignOutModal = useSignOut();

const onChangeEmail = useCallback(() => {
setAuthModal({
Expand All @@ -211,10 +208,6 @@ export const AccountSetting: FC = () => {
});
}, [account.email, account.info?.hasPassword, setAuthModal]);

const onOpenSignOutModal = useCallback(() => {
setSignOutModal(true);
}, [setSignOutModal]);

return (
<>
<SettingHeader
Expand Down Expand Up @@ -247,7 +240,7 @@ export const AccountSetting: FC = () => {
desc={t['com.affine.setting.sign.out.message']()}
style={{ cursor: 'pointer' }}
data-testid="sign-out-button"
onClick={onOpenSignOutModal}
onClick={openSignOutModal}
>
<ArrowRightSmallIcon />
</SettingRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,47 +49,6 @@ const SubscriptionChangedNotifyFooter = ({
);
};

export const useUpgradeNotify = () => {
const t = useI18n();
const prevNotifyIdRef = useRef<string | number | null>(null);

return useCallback(
(link: string) => {
prevNotifyIdRef.current && notify.dismiss(prevNotifyIdRef.current);
const id = notify(
{
title: (
<span className={notifyHeader}>
{t['com.affine.payment.upgrade-success-notify.title']()}
</span>
),
message: t['com.affine.payment.upgrade-success-notify.content'](),
alignMessage: 'title',
icon: null,
footer: (
<SubscriptionChangedNotifyFooter
to={link}
okText={
BUILD_CONFIG.isElectron
? t['com.affine.payment.upgrade-success-notify.ok-client']()
: t['com.affine.payment.upgrade-success-notify.ok-web']()
}
cancelText={t[
'com.affine.payment.upgrade-success-notify.later'
]()}
onCancel={() => notify.dismiss(id)}
onConfirm={() => notify.dismiss(id)}
/>
),
},
{ duration: 24 * 60 * 60 * 1000 }
);
prevNotifyIdRef.current = id;
},
[t]
);
};

export const useDowngradeNotify = () => {
const t = useI18n();
const prevNotifyIdRef = useRef<string | number | null>(null);
Expand Down
1 change: 0 additions & 1 deletion packages/frontend/core/src/components/atoms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const openWorkspacesModalAtom = atom(false);
/**
* @deprecated use `useSignOut` hook instated
*/
export const openSignOutModalAtom = atom(false);
export const openQuotaModalAtom = atom(false);
export const openStarAFFiNEModalAtom = atom(false);
export const openIssueFeedbackModalAtom = atom(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { useUpgradeNotify } from '@affine/core/components/affine/subscription-landing/notify';
import { SubscriptionPlan, SubscriptionRecurring } from '@affine/graphql';
import { track } from '@affine/track';
import { nanoid } from 'nanoid';
import { useCallback, useEffect } from 'react';
import { useSearchParams } from 'react-router-dom';

import { type AuthAccountInfo } from '../../../modules/cloud';

const separator = '::';
const recoverSeparator = nanoid();
const localStorageKey = 'subscription-succeed-info';

const typeFormUrl = 'https://6dxre9ihosp.typeform.com/to';
const typeFormUpgradeId = 'mUMGGQS8';
const typeFormDowngradeId = 'RvD9AoRg';
Expand Down Expand Up @@ -69,80 +63,3 @@ export const generateSubscriptionCallbackLink = (

return `${baseUrl}?info=${encodeURIComponent(query)}`;
};

/**
* Parse subscription callback query.info
* @returns
*/
export const parseSubscriptionCallbackLink = (query: string) => {
const [plan, recurring, id, email, rawName] =
decodeURIComponent(query).split(separator);
const name = rawName.replaceAll(recoverSeparator, separator);

return {
plan: plan as SubscriptionPlan,
recurring: recurring as SubscriptionRecurring,
account: {
id,
email,
info: {
name,
},
},
};
};

/**
* Hook to parse subscription callback link, and save to local storage and delete the query
*/
export const useSubscriptionNotifyWriter = () => {
const [searchParams] = useSearchParams();

useEffect(() => {
const query = searchParams.get('info');
if (query) {
localStorage.setItem(localStorageKey, query);
searchParams.delete('info');
}
}, [searchParams]);
};

/**
* Hook to read and parse subscription info from localStorage
*/
export const useSubscriptionNotifyReader = () => {
const upgradeNotify = useUpgradeNotify();

const readAndNotify = useCallback(() => {
const query = localStorage.getItem(localStorageKey);
if (!query) return;

try {
const { plan, recurring, account } = parseSubscriptionCallbackLink(query);
const link = getUpgradeQuestionnaireLink({
id: account.id,
email: account.email,
name: account.info?.name ?? '',
plan,
recurring,
});
upgradeNotify(link);
localStorage.removeItem(localStorageKey);

track.$.settingsPanel.plans.subscribe({
plan,
recurring,
});
} catch (err) {
console.error('Failed to parse subscription callback link', err);
}
}, [upgradeNotify]);

useEffect(() => {
readAndNotify();
window.addEventListener('focus', readAndNotify);
return () => {
window.removeEventListener('focus', readAndNotify);
};
}, [readAndNotify]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { AppContainer } from '../affine/app-container';
import { SyncAwareness } from '../affine/awareness';
import { appSidebarResizingAtom, SidebarSwitch } from '../app-sidebar';
import { useRegisterFindInPageCommands } from '../hooks/affine/use-register-find-in-page-commands';
import { useSubscriptionNotifyReader } from '../hooks/affine/use-subscription-notify';
import { useRegisterWorkspaceCommands } from '../hooks/use-register-workspace-commands';
import { OverCapacityNotification } from '../over-capacity';
import { CurrentWorkspaceModals } from '../providers/modal-provider';
Expand Down Expand Up @@ -141,7 +140,6 @@ export const WorkspaceLayoutProviders = ({ children }: PropsWithChildren) => {
workbench,
]);

useSubscriptionNotifyReader();
useRegisterWorkspaceCommands();
useRegisterNavigationCommands();
useRegisterFindInPageCommands();
Expand Down
Loading

0 comments on commit 7fc207d

Please sign in to comment.