mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
scroll to cell on flow view change
This commit is contained in:
parent
69c61acc41
commit
b257e9b5d9
6 changed files with 46 additions and 21 deletions
|
@ -5,3 +5,5 @@ export const isTablet = () => {
|
||||||
|
|
||||||
return window.innerWidth < 599;
|
return window.innerWidth < 599;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const headerHeight = 64; // px
|
||||||
|
|
|
@ -9,8 +9,4 @@
|
||||||
|
|
||||||
.heading {
|
.heading {
|
||||||
margin-bottom: 0.25em;
|
margin-bottom: 0.25em;
|
||||||
|
|
||||||
h4 {
|
|
||||||
// line-height: 1.1em;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { FC, useMemo } from 'react';
|
import { FC, useCallback, useMemo } from 'react';
|
||||||
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@ import { useWindowSize } from '~/hooks/dom/useWindowSize';
|
||||||
import { useFlowCellControls } from '~/hooks/flow/useFlowCellControls';
|
import { useFlowCellControls } from '~/hooks/flow/useFlowCellControls';
|
||||||
import { FlowDisplay, INode } from '~/types';
|
import { FlowDisplay, INode } from '~/types';
|
||||||
|
|
||||||
|
import { isFullyVisible } from '../../../../../utils/dom';
|
||||||
|
|
||||||
import { CellShade } from './components/CellShade';
|
import { CellShade } from './components/CellShade';
|
||||||
import { FlowCellImage } from './components/FlowCellImage';
|
import { FlowCellImage } from './components/FlowCellImage';
|
||||||
import { FlowCellMenu } from './components/FlowCellMenu';
|
import { FlowCellMenu } from './components/FlowCellMenu';
|
||||||
|
@ -25,7 +27,7 @@ interface Props {
|
||||||
text?: string;
|
text?: string;
|
||||||
flow: FlowDisplay;
|
flow: FlowDisplay;
|
||||||
canEdit?: boolean;
|
canEdit?: boolean;
|
||||||
onChangeCellView: (id: INode['id'], flow: FlowDisplay) => void;
|
onChange: (id: INode['id'], flow: FlowDisplay) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const FlowCell: FC<Props> = ({
|
const FlowCell: FC<Props> = ({
|
||||||
|
@ -37,7 +39,7 @@ const FlowCell: FC<Props> = ({
|
||||||
text,
|
text,
|
||||||
title,
|
title,
|
||||||
canEdit = false,
|
canEdit = false,
|
||||||
onChangeCellView,
|
onChange,
|
||||||
}) => {
|
}) => {
|
||||||
const { isTablet } = useWindowSize();
|
const { isTablet } = useWindowSize();
|
||||||
|
|
||||||
|
@ -45,6 +47,30 @@ const FlowCell: FC<Props> = ({
|
||||||
((!!flow.display && flow.display !== 'single') || !image) &&
|
((!!flow.display && flow.display !== 'single') || !image) &&
|
||||||
flow.show_description &&
|
flow.show_description &&
|
||||||
!!text;
|
!!text;
|
||||||
|
|
||||||
|
const {
|
||||||
|
isActive: isMenuActive,
|
||||||
|
activate,
|
||||||
|
ref,
|
||||||
|
deactivate,
|
||||||
|
} = useClickOutsideFocus();
|
||||||
|
|
||||||
|
const onChangeWithScroll = useCallback<typeof onChange>(
|
||||||
|
(...args) => {
|
||||||
|
onChange(...args);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
if (!isFullyVisible(ref.current)) {
|
||||||
|
ref.current?.scrollIntoView({
|
||||||
|
behavior: 'auto',
|
||||||
|
block: 'center',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
},
|
||||||
|
[onChange, ref],
|
||||||
|
);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
hasDescription,
|
hasDescription,
|
||||||
setViewHorizontal,
|
setViewHorizontal,
|
||||||
|
@ -52,13 +78,7 @@ const FlowCell: FC<Props> = ({
|
||||||
setViewQuadro,
|
setViewQuadro,
|
||||||
setViewSingle,
|
setViewSingle,
|
||||||
toggleViewDescription,
|
toggleViewDescription,
|
||||||
} = useFlowCellControls(id, text, flow, onChangeCellView);
|
} = useFlowCellControls(id, text, flow, onChangeWithScroll);
|
||||||
const {
|
|
||||||
isActive: isMenuActive,
|
|
||||||
activate,
|
|
||||||
ref,
|
|
||||||
deactivate,
|
|
||||||
} = useClickOutsideFocus();
|
|
||||||
|
|
||||||
const shadeSize = useMemo(() => {
|
const shadeSize = useMemo(() => {
|
||||||
const min = isTablet ? 10 : 15;
|
const min = isTablet ? 10 : 15;
|
||||||
|
|
|
@ -116,12 +116,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.display_modal {
|
.display_modal {
|
||||||
@include appear;
|
|
||||||
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
inset: 0;
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
z-index: 11;
|
z-index: 11;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ export const FlowGrid: FC<Props> = observer(
|
||||||
text={node.description}
|
text={node.description}
|
||||||
title={node.title}
|
title={node.title}
|
||||||
canEdit={fetched && isUser && canEditNode(node, user)}
|
canEdit={fetched && isUser && canEditNode(node, user)}
|
||||||
onChangeCellView={onChangeCellView}
|
onChange={onChangeCellView}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import {
|
||||||
COMMENT_BLOCK_TYPES,
|
COMMENT_BLOCK_TYPES,
|
||||||
ICommentBlock,
|
ICommentBlock,
|
||||||
} from '~/constants/comment';
|
} from '~/constants/comment';
|
||||||
|
import { headerHeight } from '~/constants/dom';
|
||||||
import { IFile, ValueOf } from '~/types';
|
import { IFile, ValueOf } from '~/types';
|
||||||
import { CONFIG } from '~/utils/config';
|
import { CONFIG } from '~/utils/config';
|
||||||
import {
|
import {
|
||||||
|
@ -213,3 +214,14 @@ export const sizeOf = (bytes: number): string => {
|
||||||
(bytes / Math.pow(1024, e)).toFixed(2) + ' ' + ' KMGTP'.charAt(e) + 'B'
|
(bytes / Math.pow(1024, e)).toFixed(2) + ' ' + ' KMGTP'.charAt(e) + 'B'
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Tells if element is in view */
|
||||||
|
export const isFullyVisible = (element?: HTMLElement): boolean => {
|
||||||
|
if (!element) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rect = element.getBoundingClientRect();
|
||||||
|
|
||||||
|
return rect?.top > headerHeight && rect?.bottom < window.innerHeight;
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue