1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00

fixed mobile appearance of dialogs

This commit is contained in:
Fedor Katurov 2022-07-14 13:26:53 +07:00
parent 4483d7a0f5
commit 042f238590
8 changed files with 25 additions and 19 deletions

View file

@ -11,7 +11,7 @@
box-sizing: border-box; box-sizing: border-box;
@include tablet { @include tablet {
padding: 70px 5px 5px 5px; padding: 20px 0 0 0;
} }
} }

View file

@ -6,10 +6,12 @@ import { Padder } from '~/components/containers/Padder';
import { EditorActionsPanel } from '~/components/editors/EditorActionsPanel'; import { EditorActionsPanel } from '~/components/editors/EditorActionsPanel';
import { Button } from '~/components/input/Button'; import { Button } from '~/components/input/Button';
import { InputText } from '~/components/input/InputText'; import { InputText } from '~/components/input/InputText';
import { useWindowSize } from '~/hooks/dom/useWindowSize';
import { useNodeFormContext } from '~/hooks/node/useNodeFormFormik'; import { useNodeFormContext } from '~/hooks/node/useNodeFormFormik';
const EditorButtons: FC = () => { const EditorButtons: FC = () => {
const { values, handleChange, isSubmitting } = useNodeFormContext(); const { values, handleChange, isSubmitting } = useNodeFormContext();
const { isMobile } = useWindowSize();
return ( return (
<Padder style={{ position: 'relative' }}> <Padder style={{ position: 'relative' }}>
@ -28,7 +30,7 @@ const EditorButtons: FC = () => {
</Filler> </Filler>
<Button <Button
title="Сохранить" title={isMobile ? undefined : 'Сохранить'}
iconRight="check" iconRight="check"
color={values.is_promoted ? 'primary' : 'lab'} color={values.is_promoted ? 'primary' : 'lab'}
disabled={isSubmitting} disabled={isSubmitting}

View file

@ -12,7 +12,7 @@ interface IProps {
} }
const ImageGrid: FC<IProps> = ({ files, setFiles, locked }) => { const ImageGrid: FC<IProps> = ({ files, setFiles, locked }) => {
const { innerWidth } = useWindowSize(); const { isMobile } = useWindowSize();
const onMove = useCallback( const onMove = useCallback(
(newFiles: IFile[]) => { (newFiles: IFile[]) => {
@ -34,7 +34,7 @@ const ImageGrid: FC<IProps> = ({ files, setFiles, locked }) => {
onSortEnd={onMove} onSortEnd={onMove}
items={files} items={files}
locked={locked} locked={locked}
size={innerWidth > 768 ? 220 : (innerWidth - 60) / 2} size={!isMobile ? 220 : (innerWidth - 60) / 2}
/> />
); );
}; };

View file

@ -39,7 +39,7 @@ const FlowCell: FC<Props> = ({
canEdit = false, canEdit = false,
onChangeCellView, onChangeCellView,
}) => { }) => {
const { innerWidth } = useWindowSize(); const { isMobile } = useWindowSize();
const withText = const withText =
((!!flow.display && flow.display !== 'single') || !image) && flow.show_description && !!text; ((!!flow.display && flow.display !== 'single') || !image) && flow.show_description && !!text;
@ -54,11 +54,11 @@ const FlowCell: FC<Props> = ({
const { isActive: isMenuActive, activate, ref, deactivate } = useClickOutsideFocus(); const { isActive: isMenuActive, activate, ref, deactivate } = useClickOutsideFocus();
const shadeSize = useMemo(() => { const shadeSize = useMemo(() => {
const min = innerWidth < 768 ? 10 : 15; const min = isMobile ? 10 : 15;
const max = innerWidth < 768 ? 20 : 50; const max = isMobile ? 20 : 50;
return withText ? min : max; return withText ? min : max;
}, [withText, innerWidth]); }, [withText, isMobile]);
return ( return (
<div className={classNames(styles.cell, styles[flow.display || 'single'])} ref={ref as any}> <div className={classNames(styles.cell, styles[flow.display || 'single'])} ref={ref as any}>

View file

@ -34,13 +34,13 @@ const lazy = {
}; };
export const FlowSwiperHero: FC<Props> = ({ heroes }) => { export const FlowSwiperHero: FC<Props> = ({ heroes }) => {
const { innerWidth } = useWindowSize(); const { isMobile } = useWindowSize();
const { push } = useNavigation(); const { push } = useNavigation();
const [controlledSwiper, setControlledSwiper] = useState<SwiperClass | undefined>(undefined); const [controlledSwiper, setControlledSwiper] = useState<SwiperClass | undefined>(undefined);
const [currentIndex, setCurrentIndex] = useState(heroes.length); const [currentIndex, setCurrentIndex] = useState(heroes.length);
const preset = useMemo(() => (innerWidth <= 768 ? ImagePresets.cover : ImagePresets.small_hero), [ const preset = useMemo(() => (isMobile ? ImagePresets.cover : ImagePresets.small_hero), [
innerWidth, isMobile,
]); ]);
const onNext = useCallback(() => { const onNext = useCallback(() => {

View file

@ -6,6 +6,7 @@ import PhotoSwipeUI_Default from 'photoswipe/dist/photoswipe-ui-default.js';
import PhotoSwipeJs from 'photoswipe/dist/photoswipe.js'; import PhotoSwipeJs from 'photoswipe/dist/photoswipe.js';
import { ImagePresets } from '~/constants/urls'; import { ImagePresets } from '~/constants/urls';
import { useWindowSize } from '~/hooks/dom/useWindowSize';
import { useModal } from '~/hooks/modal/useModal'; import { useModal } from '~/hooks/modal/useModal';
import { IFile } from '~/types'; import { IFile } from '~/types';
import { DialogComponentProps } from '~/types/modal'; import { DialogComponentProps } from '~/types/modal';
@ -21,6 +22,7 @@ export interface PhotoSwipeProps extends DialogComponentProps {
const PhotoSwipe: VFC<PhotoSwipeProps> = observer(({ index, items }) => { const PhotoSwipe: VFC<PhotoSwipeProps> = observer(({ index, items }) => {
let ref = useRef<HTMLDivElement>(null); let ref = useRef<HTMLDivElement>(null);
const { hideModal } = useModal(); const { hideModal } = useModal();
const { isMobile } = useWindowSize();
useEffect(() => { useEffect(() => {
new Promise(async resolve => { new Promise(async resolve => {
@ -32,10 +34,7 @@ const PhotoSwipe: VFC<PhotoSwipeProps> = observer(({ index, items }) => {
img.onload = () => { img.onload = () => {
resolveImage({ resolveImage({
src: getURL( src: getURL(image, isMobile ? ImagePresets[900] : ImagePresets[1600]),
image,
window.innerWidth < 768 ? ImagePresets[900] : ImagePresets[1600]
),
h: img.naturalHeight, h: img.naturalHeight,
w: img.naturalWidth, w: img.naturalWidth,
}); });
@ -62,7 +61,7 @@ const PhotoSwipe: VFC<PhotoSwipeProps> = observer(({ index, items }) => {
ps.listen('destroy', hideModal); ps.listen('destroy', hideModal);
ps.listen('close', hideModal); ps.listen('close', hideModal);
}); });
}, [hideModal, items, index]); }, [hideModal, items, index, isMobile]);
return ( return (
<div className="pswp" tabIndex={-1} role="dialog" aria-hidden="true" ref={ref}> <div className="pswp" tabIndex={-1} role="dialog" aria-hidden="true" ref={ref}>

View file

@ -1,10 +1,15 @@
import { useCallback, useEffect, useState } from 'react'; import { useCallback, useEffect, useState } from 'react';
export const useWindowSize = () => { export const useWindowSize = () => {
const [size, setSize] = useState({ innerWidth: 0, innerHeight: 0 }); const [size, setSize] = useState({ innerWidth: 0, innerHeight: 0, isMobile: false });
const onResize = useCallback( const onResize = useCallback(
() => setSize({ innerWidth: window.innerWidth, innerHeight: window.innerHeight }), () =>
setSize({
innerWidth: window.innerWidth,
innerHeight: window.innerHeight,
isMobile: window.innerWidth < 768,
}),
[] []
); );

File diff suppressed because one or more lines are too long