Merge branch 'feat/datacenter' into feat/datacenter-i18n

This commit is contained in:
JimmFly 2023-02-01 10:25:02 +08:00
commit 720aa6e6b0
10 changed files with 27 additions and 107 deletions

View File

@ -2,15 +2,15 @@ import { Modal, ModalWrapper, ModalCloseButton } from '@/ui/modal';
import { Wrapper } from '@/ui/layout';
import { useState } from 'react';
import { CreateWorkspaceModal } from '../create-workspace';
import { Tooltip } from '@/ui/tooltip';
import { toast } from '@/ui/toast';
import { AddIcon, HelpCenterIcon } from '@blocksuite/icons';
import { useAppState } from '@/providers/app-state-provider';
import { useRouter } from 'next/router';
import { useTranslation } from '@affine/i18n';
import { LanguageMenu } from './LanguageMenu';
import { LanguageMenu } from './SelectLanguageMenu';
import { LoginModal } from '../login-modal';
import { LogoutModal } from '../logout-modal';
@ -29,7 +29,6 @@ import {
} from './styles';
import { WorkspaceCard } from './WorkspaceCard';
import { Footer } from './Footer';
import { useConfirm } from '@/providers/ConfirmProvider';
interface WorkspaceModalProps {
open: boolean;
onClose: () => void;
@ -42,7 +41,6 @@ export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => {
const { t } = useTranslation();
const [loginOpen, setLoginOpen] = useState(false);
const [logoutOpen, setLogoutOpen] = useState(false);
const { confirm } = useConfirm();
return (
<>
@ -117,19 +115,7 @@ export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => {
setLoginOpen(true);
}}
onLogout={() => {
setLoginOpen(true);
confirm({
title: 'Sign out?',
content: `All data has been stored in the cloud. `,
confirmText: 'Sign out',
cancelText: 'Cancel',
}).then(async confirm => {
if (confirm) {
await logout();
await router.replace(`/workspace`);
toast('Enabled success');
}
});
setLogoutOpen(true);
}}
/>
</ModalWrapper>

View File

@ -1,61 +0,0 @@
import { LOCALES } from '@affine/i18n';
import { styled } from '@/styles';
import { useTranslation } from '@affine/i18n';
import { ArrowDownIcon } from '@blocksuite/icons';
import { Button } from '@/ui/button';
import { Menu, MenuItem } from '@/ui/menu';
const LanguageMenuContent = () => {
const { i18n } = useTranslation();
const changeLanguage = (event: string) => {
i18n.changeLanguage(event);
};
return (
<>
{LOCALES.map(option => {
return (
<ListItem
key={option.name}
title={option.name}
onClick={() => {
changeLanguage(option.tag);
}}
>
{option.originalName}
</ListItem>
);
})}
</>
);
};
export const LanguageMenu = () => {
const { i18n } = useTranslation();
const currentLanguage = LOCALES.find(item => item.tag === i18n.language);
return (
<Menu
content={<LanguageMenuContent />}
placement="bottom"
trigger="click"
disablePortal={true}
>
<Button
icon={<ArrowDownIcon />}
iconPosition="end"
noBorder={true}
style={{ textTransform: 'capitalize' }}
>
{currentLanguage?.originalName}
</Button>
</Menu>
);
};
const ListItem = styled(MenuItem)(({ theme }) => ({
height: '38px',
color: theme.colors.popoverColor,
fontSize: theme.font.sm,
textTransform: 'capitalize',
padding: '0 24px',
}));

View File

@ -10,7 +10,6 @@ import { useState } from 'react';
import { Button } from '@/ui/button';
import Input from '@/ui/input';
import { toast } from '@/ui/toast';
// import { useAppState } from '@/providers/app-state-provider3';
import { WorkspaceUnit } from '@affine/datacenter';
import { useWorkspaceHelper } from '@/hooks/use-workspace-helper';
import { useTranslation } from '@affine/i18n';
@ -23,6 +22,7 @@ export const PublishPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
const togglePublic = async (flag: boolean) => {
try {
await publishWorkspace(workspace.id.toString(), flag);
setLoaded(false);
} catch (e) {
toast(t('Failed to publish workspace'));
}
@ -66,7 +66,6 @@ export const PublishPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
onClick={async () => {
setLoaded(true);
await togglePublic(true);
setLoaded(false);
}}
loading={loaded}
type="primary"
@ -85,7 +84,6 @@ export const PublishPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
onClick={async () => {
setLoaded(true);
await togglePublic(false);
setLoaded(true);
}}
loading={false}
type="danger"

View File

@ -9,11 +9,13 @@ import { DownloadIcon } from '@blocksuite/icons';
import { Button } from '@/ui/button';
import { Menu, MenuItem } from '@/ui/menu';
import { WorkspaceUnit } from '@affine/datacenter';
import { Trans, useTranslation } from '@affine/i18n';
import { useTranslation, Trans } from '@affine/i18n';
import { WorkspaceUnitAvatar } from '@/components/workspace-avatar';
import { EnableWorkspaceButton } from '../enable-workspace';
import { useAppState } from '@/providers/app-state-provider';
export const SyncPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
const { t } = useTranslation();
const { user } = useAppState();
return (
<div>
<StyledPublishContent>
@ -51,7 +53,7 @@ export const SyncPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
All data will be synchronised and saved to the AFFiNE account
<StyledEmail>
{{
email: '{' + workspace.owner?.email + '}.',
email: '{' + user?.email + '}.',
}}
</StyledEmail>
</Trans>

View File

@ -148,5 +148,6 @@ export const StyledPublishContent = styled('div')(({ theme }) => {
flexDirection: 'column',
fontSize: theme.font.base,
lineHeight: theme.font.lineHeightBase,
flex: 1,
};
});

View File

@ -16,7 +16,6 @@ import {
SearchIcon,
AllPagesIcon,
FavouritesIcon,
ImportIcon,
TrashIcon,
AddIcon,
SettingsIcon,
@ -65,7 +64,7 @@ const FavoriteList = ({ showList }: { showList: boolean }) => {
);
};
export const WorkSpaceSliderBar = () => {
const { triggerQuickSearchModal, triggerImportModal } = useModal();
const { triggerQuickSearchModal } = useModal();
const [showSubFavorite, setShowSubFavorite] = useState(true);
const { currentWorkspace } = useAppState();
const { openPage, createPage } = usePageHelper();
@ -161,14 +160,14 @@ export const WorkSpaceSliderBar = () => {
setShowWorkspaceSetting(false);
}}
/> */}
<StyledListItem
{/* TODO: will finish the feature next version */}
{/* <StyledListItem
onClick={() => {
triggerImportModal();
}}
>
<ImportIcon /> {t('Import')}
</StyledListItem>
</StyledListItem> */}
<Link href={{ pathname: paths.trash }}>
<StyledListItem active={router.asPath === paths.trash}>

View File

@ -33,8 +33,8 @@ export const useWorkspaceHelper = () => {
await dataCenter.updateWorkspaceMeta({ name }, workspace);
}
if (avatarBlob) {
// const blobId = await dataCenter.setBlob(workspace, avatarBlob);
// await dataCenter.updateWorkspaceMeta({ avatar: blobId }, workspace);
const blobId = await dataCenter.setBlob(workspace, avatarBlob);
await dataCenter.updateWorkspaceMeta({ avatar: blobId }, workspace);
}
};

View File

@ -10,7 +10,6 @@ import {
GeneralPage,
MembersPage,
PublishPage,
ExportPage,
SyncPage,
} from '@/components/workspace-setting';
import { SettingsIcon } from '@blocksuite/icons';
@ -43,11 +42,11 @@ const useTabMap = () => {
name: t('Publish'),
panelRender: workspace => <PublishPage workspace={workspace} />,
},
{
name: t('Export'),
panelRender: workspace => <ExportPage workspace={workspace} />,
},
// TODO: next version will finish this feature
// {
// name: t('Export'),
// panelRender: workspace => <ExportPage workspace={workspace} />,
// },
];
const [activeTab, setActiveTab] = useState<string>(tabMap[0].name);
const handleTabChange = (tab: string) => {

View File

@ -100,17 +100,13 @@ class Token {
static parse(token: string): AccessTokenMessage | null {
try {
return JSON.parse(
String.fromCharCode.apply(
null,
Array.from(
Uint8Array.from(
window.atob(
// split jwt
token.split('.')[1]
),
c => c.charCodeAt(0)
)
)
decodeURIComponent(
atob(token.split('.')[1])
.split('')
.map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
})
.join('')
)
);
} catch (error) {