chore: remove currentWorkspaceId & currentMetaWorkspace

This commit is contained in:
QiShaoXuan
2023-01-11 16:33:25 +08:00
parent 8e8e18fdf9
commit 926bb7fd14
19 changed files with 37 additions and 116 deletions
@@ -8,7 +8,7 @@ import { useTranslation } from '@affine/i18n';
export const TrashButtonGroup = () => {
const { permanentlyDeletePage } = usePageHelper();
const { currentWorkspaceId } = useAppState();
const { currentWorkspace } = useAppState();
const { toggleDeletePage } = usePageHelper();
const { confirm } = useConfirm();
const router = useRouter();
@@ -38,7 +38,7 @@ export const TrashButtonGroup = () => {
confirmType: 'danger',
}).then(confirm => {
if (confirm) {
router.push(`/workspace/${currentWorkspaceId}/all`);
router.push(`/workspace/${currentWorkspace?.id}/all`);
permanentlyDeletePage(id);
}
});
@@ -73,7 +73,7 @@ export const PageList = ({
isTrash?: boolean;
}) => {
const router = useRouter();
const { currentWorkspaceId } = useAppState();
const { currentWorkspace } = useAppState();
const { t } = useTranslation();
if (pageList.length === 0) {
return <Empty />;
@@ -99,7 +99,7 @@ export const PageList = ({
key={`${pageMeta.id}-${index}`}
onClick={() => {
router.push(
`/workspace/${currentWorkspaceId}/${pageMeta.id}`
`/workspace/${currentWorkspace?.id}/${pageMeta.id}`
);
}}
>
@@ -17,10 +17,8 @@ export const Input = (props: {
const [isComposition, setIsComposition] = useState(false);
const [inputValue, setInputValue] = useState('');
const inputRef = useRef<HTMLInputElement>(null);
const { currentWorkspaceId, workspaceList, currentWorkspace } = useAppState();
const isPublish = workspaceList.find(
meta => String(meta.id) === String(currentWorkspaceId)
)?.published;
const { currentWorkspace } = useAppState();
useEffect(() => {
inputRef.current?.addEventListener(
'blur',
@@ -79,7 +77,7 @@ export const Input = (props: {
}
}}
placeholder={
isPublish
currentWorkspace?.isPublish
? `Search in ${currentWorkspace?.blocksuiteWorkspace?.meta.name}`
: 'Quick Search...'
}
@@ -22,9 +22,9 @@ export const Results = (props: {
const { triggerQuickSearchModal } = useModal();
const { openPage } = usePageHelper();
const router = useRouter();
const { currentWorkspaceId, pageList } = useAppState();
const { currentWorkspace, pageList } = useAppState();
const { search } = usePageHelper();
const List = useSwitchToConfig(currentWorkspaceId);
const List = useSwitchToConfig(currentWorkspace?.id);
const [results, setResults] = useState(new Map<string, string | undefined>());
const { t } = useTranslation();
useEffect(() => {
@@ -1,15 +1,16 @@
import { FC, SVGProps } from 'react';
import { AllPagesIcon, FavouritesIcon, TrashIcon } from '@blocksuite/icons';
import { useTranslation } from '@affine/i18n';
export const useSwitchToConfig = (
currentWorkspaceId: string
currentWorkspaceId?: string
): {
title: string;
href: string;
icon: React.FC<React.SVGProps<SVGSVGElement>>;
icon: FC<SVGProps<SVGSVGElement>>;
}[] => {
const { t } = useTranslation();
const List = [
return [
{
title: t('All pages'),
href: currentWorkspaceId ? `/workspace/${currentWorkspaceId}/all` : '',
@@ -28,5 +29,4 @@ export const useSwitchToConfig = (
icon: TrashIcon,
},
];
return List;
};
@@ -22,15 +22,13 @@ const isMac = () => {
return getUaHelper().isMacOs;
};
export const QuickSearch = ({ open, onClose }: TransitionsModalProps) => {
const { currentMetaWorkSpace } = useAppState();
const { currentWorkspace } = useAppState();
const [query, setQuery] = useState('');
const [loading, setLoading] = useState(true);
const [showCreatePage, setShowCreatePage] = useState(true);
const { triggerQuickSearchModal } = useModal();
const isPublish = currentMetaWorkSpace?.published;
// Add ‘⌘+K shortcut keys as switches
useEffect(() => {
const down = (e: KeyboardEvent) => {
@@ -96,7 +94,7 @@ export const QuickSearch = ({ open, onClose }: TransitionsModalProps) => {
setShowCreatePage={setShowCreatePage}
/>
</StyledContent>
{isPublish ? (
{currentWorkspace?.isPublish ? (
<></>
) : showCreatePage ? (
<>
@@ -34,8 +34,6 @@ import { useConfirm } from '@/providers/ConfirmProvider';
export const MembersPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
const [isInviteModalShow, setIsInviteModalShow] = useState(false);
// const { currentMetaWorkSpace, currentWorkspace, dataCenter } = useAppState();
const [members, setMembers] = useState<[{ name: string; email: string }?]>(
[]
);
@@ -41,7 +41,6 @@ export const GeneralPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
setShowLeave(false);
};
const handleUpdateWorkspaceName = () => {
console.log('currentWorkspace: ', currentWorkspace);
currentWorkspace &&
updateWorkspace({ name: workspaceName }, currentWorkspace);
};
@@ -5,7 +5,7 @@ import { WorkspaceAvatar } from '@/components/workspace-avatar';
import { useAppState } from '@/providers/app-state-provider';
export const WorkspaceSelector = () => {
const [workspaceListShow, setWorkspaceListShow] = useState(false);
const { currentMetaWorkSpace, workspaceList } = useAppState();
const { currentWorkspace, workspaceList } = useAppState();
useEffect(() => {
if (workspaceList.length === 0) {
@@ -23,7 +23,7 @@ export const WorkspaceSelector = () => {
<Avatar
alt="Affine"
data-testid="workspace-avatar"
src={currentMetaWorkSpace?.avatar}
src={currentWorkspace?.avatar}
>
<div
style={{
@@ -32,13 +32,13 @@ export const WorkspaceSelector = () => {
>
<WorkspaceAvatar
size={28}
name={currentMetaWorkSpace?.name ?? 'AFFiNE'}
avatar={currentMetaWorkSpace?.avatar ?? ''}
name={currentWorkspace?.name ?? 'AFFiNE'}
avatar={currentWorkspace?.avatar ?? ''}
/>
</div>
</Avatar>
<WorkspaceName data-testid="workspace-name">
{currentMetaWorkSpace?.name ?? 'AFFiNE'}
{currentWorkspace?.name ?? 'AFFiNE'}
</WorkspaceName>
</SelectorWrapper>
<WorkspaceModal
@@ -67,13 +67,13 @@ const FavoriteList = ({ showList }: { showList: boolean }) => {
export const WorkSpaceSliderBar = () => {
const { triggerQuickSearchModal, triggerImportModal } = useModal();
const [showSubFavorite, setShowSubFavorite] = useState(true);
const { currentWorkspaceId } = useAppState();
const { currentWorkspace } = useAppState();
const { openPage, createPage } = usePageHelper();
const router = useRouter();
const { t } = useTranslation();
const [showTip, setShowTip] = useState(false);
const [show, setShow] = useLocalStorage('AFFiNE_SLIDE_BAR', false, true);
const currentWorkspaceId = currentWorkspace?.id;
const paths = {
all: currentWorkspaceId ? `/workspace/${currentWorkspaceId}/all` : '',
favorite: currentWorkspaceId