opti: 1.adjust layout style;

This commit is contained in:
mitsuha
2022-08-04 17:20:03 +08:00
parent 78ee91583a
commit 5b682188a8
7 changed files with 123 additions and 126 deletions
@@ -1,16 +1,9 @@
/* eslint-disable filename-rules/match */ /* eslint-disable filename-rules/match */
import { import { useEffect, useRef, type UIEvent, useState } from 'react';
useEffect,
useRef,
type UIEvent,
useState,
useLayoutEffect,
} from 'react';
import { useParams } from 'react-router'; import { useParams } from 'react-router';
import { import {
MuiBox as Box, MuiBox as Box,
MuiCircularProgress as CircularProgress, MuiCircularProgress as CircularProgress,
MuiDivider as Divider,
styled, styled,
} from '@toeverything/components/ui'; } from '@toeverything/components/ui';
import { AffineEditor } from '@toeverything/components/affine-editor'; import { AffineEditor } from '@toeverything/components/affine-editor';
@@ -54,11 +47,11 @@ export function Page(props: PageProps) {
} }
); );
// await services.api.userConfig.addRecentPage( await services.api.userConfig.addRecentPage(
// props.workspace, props.workspace,
// user.id, user.id,
// page_id page_id
// ); );
await services.api.editorBlock.clearUndoRedo(props.workspace); await services.api.editorBlock.clearUndoRedo(props.workspace);
}; };
updateRecentPages(); updateRecentPages();
@@ -94,14 +87,14 @@ export function Page(props: PageProps) {
)} )}
<div> <div>
<CollapsibleTitle <CollapsibleTitle
title="Activities" title="ACTIVITIES"
initialOpen={false} initialOpen={false}
> >
<Activities /> <Activities />
</CollapsibleTitle> </CollapsibleTitle>
</div> </div>
<div> <div>
<CollapsiblePageTree title="Page Tree"> <CollapsiblePageTree title="PAGES">
{page_id ? <PageTree /> : null} {page_id ? <PageTree /> : null}
</CollapsiblePageTree> </CollapsiblePageTree>
</div> </div>
@@ -1,34 +1,34 @@
import { useCallback, useState } from 'react'; import React, { useCallback, useState } from 'react';
import { useNavigate, useParams } from 'react-router-dom'; import { useNavigate, useParams } from 'react-router-dom';
import clsx from 'clsx';
import style9 from 'style9';
import { import {
MuiBox as Box, MuiBox as Box,
MuiButton as Button, MuiButton as Button,
MuiCollapse as Collapse, MuiCollapse as Collapse,
MuiIconButton as IconButton, MuiIconButton as IconButton,
styled,
} from '@toeverything/components/ui'; } from '@toeverything/components/ui';
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown'; import {
import ArrowRightIcon from '@mui/icons-material/ArrowRight'; ArrowDropDownIcon,
ArrowRightIcon,
} from '@toeverything/components/icons';
import { services } from '@toeverything/datasource/db-service'; import { services } from '@toeverything/datasource/db-service';
import { NewpageIcon } from '@toeverything/components/common';
import { import {
usePageTree, usePageTree,
useCalendarHeatmap, useCalendarHeatmap,
} from '@toeverything/components/layout'; } from '@toeverything/components/layout';
import { AddIcon } from '@toeverything/components/icons';
const styles = style9.create({ const StyledContainer = styled('div')({
ligoButton: { height: '32px',
textTransform: 'none', display: 'flex',
}, alignItems: 'center',
newPage: { });
color: '#B6C7D3',
width: '26px', const StyledBtn = styled('div')({
fontSize: '18px', color: '#98ACBD',
textAlign: 'center', textTransform: 'none',
cursor: 'pointer', fontSize: '12px',
}, fontWeight: '600',
}); });
export type CollapsiblePageTreeProps = { export type CollapsiblePageTreeProps = {
@@ -73,31 +73,35 @@ export function CollapsiblePageTree(props: CollapsiblePageTreeProps) {
justifyContent: 'space-between', justifyContent: 'space-between',
alignItems: 'center', alignItems: 'center',
paddingRight: 1, paddingRight: 1,
'&:hover': {
background: '#f5f7f8',
borderRadius: '5px',
},
}} }}
onMouseEnter={() => setNewPageBtnVisible(true)} onMouseEnter={() => setNewPageBtnVisible(true)}
onMouseLeave={() => setNewPageBtnVisible(false)} onMouseLeave={() => setNewPageBtnVisible(false)}
> >
<Button <StyledContainer>
startIcon={ {open ? (
open ? <ArrowDropDownIcon /> : <ArrowRightIcon /> <ArrowDropDownIcon sx={{ color: '#566B7D' }} />
} ) : (
onClick={() => setOpen(prev => !prev)} <ArrowRightIcon sx={{ color: '#566B7D' }} />
sx={{ color: '#566B7D', textTransform: 'none' }} )}
className={clsx(styles('ligoButton'), className)} <StyledBtn onClick={() => setOpen(prev => !prev)}>
style={style} {title}
disableElevation </StyledBtn>
disableRipple </StyledContainer>
>
{title}
</Button>
{newPageBtnVisible && ( {newPageBtnVisible && (
<div <AddIcon
style={{
width: '20px',
height: '20px',
color: '#98ACBD',
cursor: 'pointer',
}}
onClick={create_page} onClick={create_page}
className={clsx(styles('newPage'), className)} />
>
+
</div>
)} )}
</Box> </Box>
{children ? ( {children ? (
@@ -1,16 +1,21 @@
import { useState } from 'react'; import { useState } from 'react';
import clsx from 'clsx';
import style9 from 'style9';
import { import {
MuiButton as Button, MuiButton as Button,
MuiCollapse as Collapse, MuiCollapse as Collapse,
styled,
} from '@toeverything/components/ui'; } from '@toeverything/components/ui';
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown'; import {
import ArrowRightIcon from '@mui/icons-material/ArrowRight'; ArrowDropDownIcon,
ArrowRightIcon,
} from '@toeverything/components/icons';
const styles = style9.create({ const StyledContainer = styled('div')({
ligoButton: { display: 'flex',
textTransform: 'none', alignItems: 'center',
cursor: 'pointer',
'&:hover': {
background: '#f5f7f8',
borderRadius: '5px',
}, },
}); });
@@ -24,29 +29,32 @@ export type CollapsibleTitleProps = {
}; };
export function CollapsibleTitle(props: CollapsibleTitleProps) { export function CollapsibleTitle(props: CollapsibleTitleProps) {
const { className, style, children, title, initialOpen = true } = props; const { children, title, initialOpen = true } = props;
const [open, setOpen] = useState(initialOpen); const [open, setOpen] = useState(initialOpen);
return ( return (
<> <>
<Button <StyledContainer onClick={() => setOpen(prev => !prev)}>
startIcon={ {open ? (
open ? ( <ArrowDropDownIcon sx={{ color: '#566B7D' }} />
<ArrowDropDownIcon sx={{ color: '#566B7D' }} /> ) : (
) : ( <ArrowRightIcon sx={{ color: '#566B7D' }} />
<ArrowRightIcon sx={{ color: '#566B7D' }} /> )}
) <div
} style={{
onClick={() => setOpen(prev => !prev)} color: '#98ACBD',
sx={{ color: '#566B7D', textTransform: 'none' }} textTransform: 'none',
className={clsx(styles('ligoButton'), className)} fontSize: '12px',
style={style} fontWeight: '600',
disableElevation height: '32px',
disableRipple display: 'flex',
> alignItems: 'center',
{title} }}
</Button> >
{title}
</div>
</StyledContainer>
{children ? ( {children ? (
<Collapse in={open} timeout="auto" unmountOnExit> <Collapse in={open} timeout="auto" unmountOnExit>
{children} {children}
@@ -12,17 +12,22 @@ import { useNavigate } from 'react-router';
import { formatDistanceToNow } from 'date-fns'; import { formatDistanceToNow } from 'date-fns';
const StyledWrapper = styled('div')({ const StyledWrapper = styled('div')({
margin: '0 16px 0 32px', paddingLeft: '12px',
span: { span: {
textOverflow: 'ellipsis', textOverflow: 'ellipsis',
overflow: 'hidden', overflow: 'hidden',
}, },
'.item': { '.item': {
height: '32px',
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',
ustifyContent: 'space-between', justifyContent: 'space-between',
padding: '7px 0px', paddingRight: '20px',
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
'&:hover': {
background: '#f5f7f8',
borderRadius: '5px',
},
}, },
'.itemButton': { '.itemButton': {
padding: 0, padding: 0,
@@ -31,6 +36,7 @@ const StyledWrapper = styled('div')({
'.itemLeft': { '.itemLeft': {
color: '#4c6275', color: '#4c6275',
marginRight: '20px', marginRight: '20px',
cursor: 'pointer',
span: { span: {
fontSize: 14, fontSize: 14,
}, },
@@ -44,6 +50,14 @@ const StyledWrapper = styled('div')({
}, },
}); });
const StyledItemContent = styled('div')({
width: '100%',
height: '32px',
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
});
export const Activities = () => { export const Activities = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const { user, currentSpaceId } = useUserAndSpaces(); const { user, currentSpaceId } = useUserAndSpaces();
@@ -51,34 +65,29 @@ export const Activities = () => {
const userId = user?.id; const userId = user?.id;
/* temporarily remove:show recently viewed documents */ /* temporarily remove:show recently viewed documents */
// const fetchRecentPages = useCallback(async () => { const fetchRecentPages = useCallback(async () => {
// if (!userId || !currentSpaceId) { if (!userId || !currentSpaceId) {
// return; return;
// } }
// const recent_pages = await services.api.userConfig.getRecentPages( const recent_pages = await services.api.userConfig.getRecentPages(
// currentSpaceId, currentSpaceId,
// userId userId
// ); );
// setRecentPages(recent_pages); setRecentPages(recent_pages);
// }, [userId, currentSpaceId]); }, [userId, currentSpaceId]);
// useEffect(() => { useEffect(() => {
// (async () => { (async () => {
// await fetchRecentPages(); await fetchRecentPages();
// })(); })();
// }, [fetchRecentPages]); }, [fetchRecentPages]);
/* show recently edit documents */
const getRecentEditPages = async (state, block) => {
console.log(state, await block.children());
};
useEffect(() => { useEffect(() => {
let unobserve: () => void; let unobserve: () => void;
const observe = async () => { const observe = async () => {
unobserve = await services.api.userConfig.observe( unobserve = await services.api.userConfig.observe(
{ workspace: currentSpaceId }, { workspace: currentSpaceId },
getRecentEditPages fetchRecentPages
); );
}; };
observe(); observe();
@@ -86,16 +95,15 @@ export const Activities = () => {
return () => { return () => {
unobserve?.(); unobserve?.();
}; };
}, [currentSpaceId, getRecentEditPages]); }, [currentSpaceId, fetchRecentPages]);
return ( return (
<StyledWrapper> <StyledWrapper>
<List> <List style={{ padding: '0px' }}>
{recentPages.map(({ id, title, lastOpenTime }) => { {recentPages.map(({ id, title, lastOpenTime }) => {
return ( return (
<ListItem className="item" key={id}> <ListItem className="item" key={id}>
<ListItemButton <StyledItemContent
className="itemButton"
onClick={() => { onClick={() => {
navigate(`/${currentSpaceId}/${id}`); navigate(`/${currentSpaceId}/${id}`);
}} }}
@@ -110,7 +118,7 @@ export const Activities = () => {
includeSeconds: true, includeSeconds: true,
})} })}
/> />
</ListItemButton> </StyledItemContent>
</ListItem> </ListItem>
); );
})} })}
@@ -44,7 +44,7 @@ export type DndTreeProps = {
*/ */
export function DndTree(props: DndTreeProps) { export function DndTree(props: DndTreeProps) {
const { const {
indentationWidth = 16, indentationWidth = 12,
collapsible, collapsible,
removable, removable,
showDragIndicator, showDragIndicator,
@@ -101,9 +101,6 @@ export const TreeItem = forwardRef<HTMLDivElement, TreeItemProps>(
<ArrowDropDownIcon /> <ArrowDropDownIcon />
))} ))}
</Action> </Action>
{/*<Action>*/}
{/* <DocumentIcon />*/}
{/*</Action>*/}
<div className={styles['ItemContent']}> <div className={styles['ItemContent']}>
<span <span
@@ -161,7 +158,6 @@ export function Action({
style={ style={
{ {
...style, ...style,
// cursor,
'--fill': active?.fill, '--fill': active?.fill,
'--background': active?.background, '--background': active?.background,
} as CSSProperties } as CSSProperties
@@ -4,6 +4,10 @@
list-style: none; list-style: none;
padding: 6px 0; padding: 6px 0;
font-size: 14px; font-size: 14px;
&:hover {
background: #f5f7f8;
border-radius: 5px;
}
&.clone { &.clone {
display: inline-block; display: inline-block;
@@ -43,7 +47,6 @@
height: 12px; height: 12px;
border-radius: 50%; border-radius: 50%;
border: 1px solid #2389ff; border: 1px solid #2389ff;
background-color: #ffffff;
} }
> * { > * {
@@ -69,7 +72,6 @@
box-sizing: border-box; box-sizing: border-box;
display: flex; display: flex;
align-items: center; align-items: center;
background-color: #fff;
color: #4c6275; color: #4c6275;
} }
@@ -81,7 +83,6 @@
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-around; justify-content: space-around;
background-color: #fff;
color: #4c6275; color: #4c6275;
padding-right: 0.5rem; padding-right: 0.5rem;
overflow: hidden; overflow: hidden;
@@ -96,11 +97,6 @@
display: block; display: block;
} }
} }
&:hover {
background: #f5f7f8;
border-radius: 5px;
}
} }
.Text { .Text {
@@ -167,14 +163,6 @@
background-color: transparent; background-color: transparent;
-webkit-tap-highlight-color: transparent; -webkit-tap-highlight-color: transparent;
&:hover {
background-color: var(--action-background, rgba(0, 0, 0, 0.05));
svg {
fill: #6f7b88;
}
}
svg { svg {
flex: 0 0 auto; flex: 0 0 auto;
margin: auto; margin: auto;