Skip to content

Commit

Permalink
feat: rewrite codebase for better responsiveness
Browse files Browse the repository at this point in the history
  • Loading branch information
frederic-maury committed Dec 29, 2024
1 parent 761a643 commit a3595d0
Show file tree
Hide file tree
Showing 30 changed files with 388 additions and 181 deletions.
2 changes: 1 addition & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Provider } from 'react-redux';
import './i18next/i18next';
import store from './store/store';
import { MapWrapper } from './components/Map/MapWrapper';
import { AppActions } from './components/Settings/AppActions';
import { AppActions } from './components/Settings/AppActions/AppActions';
import { MantineProviders } from './providers/MantineProvider';
import { HotkeysProvider } from './providers/HotkeysProvider';
import InitStoreProvider from './providers/InitStoreProvider';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Affix, Flex } from "@mantine/core";
import { useViewportSize } from "@mantine/hooks";
import { Affix } from "@mantine/core";
import { useSmallScreen } from "../../../hooks/useSmallScreen";
import { SmallScreen } from "./SmallScreen";

export function AffixBtn({
children,
Expand All @@ -16,21 +17,13 @@ export function AffixBtn({
leftSection?: React.ReactNode;
rightSection?: React.ReactNode;
}) {
const { width } = useViewportSize();
const isSmallScreen = useSmallScreen();

return (
<>
{
width < 768
? <Affix position={position}>
<Flex gap="sm" className="w-screen" justify={
position.right ? "end" : "start"
}>
{ leftSection }
{ children }
{ rightSection }
</Flex>
</Affix>
isSmallScreen
? <SmallScreen position={position} leftSection={leftSection} rightSection={rightSection}>{ children }</SmallScreen>
: defaultToPlain
? children
: <Affix position={widePosition}>
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/components/Common/AffixBtn/SmallScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Flex, Affix } from "@mantine/core";

export function SmallScreen(props: {
children: React.ReactNode;
leftSection?: React.ReactNode;
rightSection?: React.ReactNode;
position: { bottom?: number; right?: number; top?: number; left?: number; };
}) {
const { children, leftSection, rightSection, position } = props;

return (
<Affix position={position}>
<Flex gap="sm" className="w-screen" justify={
position.right ? "end" : "start"
}>
{ leftSection }
{ children }
{ rightSection }
</Flex>
</Affix>
)
}
8 changes: 4 additions & 4 deletions frontend/src/components/Filtering/PropertyOccupations.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { NumberInput } from "@mantine/core";
import { useTranslation } from "react-i18next";
import { useMediaQuery } from "@mantine/hooks";
import { selectPropertyOccupations } from "../../store/filtering/filteringSelector";
import { useAppDispatch, useAppSelector } from "../../hooks/useInitStore";
import { setPropertyOccupations } from "../../store/filtering/filteringReducer";
import { useSmallScreen } from "../../hooks/useSmallScreen";

export function PropertyOccupations() {
const mediaQuerySize = useMediaQuery('(max-width: 768px)') ? 'xl' : 'md';
const isSmallScreen = useSmallScreen();
const { t } = useTranslation('common', { keyPrefix: 'filtering' });

const dispatch = useAppDispatch();
Expand All @@ -28,7 +28,7 @@ export function PropertyOccupations() {
min={0}
max={propertyOccupations.max}
allowDecimal={false}
size={mediaQuerySize}
size={isSmallScreen ? 'md' : 'xl'}
onChange={(e) => onPropertyOccupations(e as number)}
/>
<NumberInput
Expand All @@ -38,7 +38,7 @@ export function PropertyOccupations() {
min={propertyOccupations.min}
max={100}
allowDecimal={false}
size={mediaQuerySize}
size={isSmallScreen ? 'md' : 'xl'}
onChange={(e) => onPropertyOccupations(undefined, e as number)}
/>
</>
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/Filtering/PropertyType.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { useAppSelector } from "../../hooks/useInitStore";
import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { ComboboxData, MultiSelect } from "@mantine/core";
import { useAppSelector } from "../../hooks/useInitStore";
import { analyticsEvent } from "../../services/analytics";
import { useAppDispatch } from "../../hooks/useInitStore";
import { selectPropertyTypes } from "../../store/filtering/filteringSelector";
import { ComboboxData, MultiSelect } from "@mantine/core";
import { setPropertyTypes } from "../../store/filtering/filteringReducer";
import { useMemo } from "react";
import { useMediaQuery } from "@mantine/hooks";
import { useSmallScreen } from "../../hooks/useSmallScreen";

export function PropertyType() {
const mediaQuerySize = useMediaQuery('(max-width: 768px)') ? 'xl' : 'md';
const isSmallScreen = useSmallScreen();
const { t } = useTranslation('common', { keyPrefix: 'filtering' });
const { t: tPropertyType } = useTranslation('common', { keyPrefix: 'propertyType' });
const dispatch = useAppDispatch();
Expand All @@ -35,7 +35,7 @@ export function PropertyType() {
label={t('propertyTypes')}
data={data}
value={propertyTypes}
size={mediaQuerySize}
size={isSmallScreen ? 'md' : 'xl'}
onChange={(e) => onPropertyTypes(e)} />
)
}
8 changes: 4 additions & 4 deletions frontend/src/components/Filtering/PropertyYields.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { NumberInput } from "@mantine/core";
import { useTranslation } from "react-i18next";
import { useMediaQuery } from "@mantine/hooks";
import { useSmallScreen } from "../../hooks/useSmallScreen";
import { selectPropertyYields } from "../../store/filtering/filteringSelector";
import { useAppDispatch, useAppSelector } from "../../hooks/useInitStore";
import { setPropertyYields } from "../../store/filtering/filteringReducer";

export function PropertyYields() {
const mediaQuerySize = useMediaQuery('(max-width: 768px)') ? 'xl' : 'md';
const isSmallScreen = useSmallScreen();
const { t } = useTranslation('common', { keyPrefix: 'filtering' });

const dispatch = useAppDispatch();
Expand All @@ -30,7 +30,7 @@ export function PropertyYields() {
min={0}
max={propertyYields.max ?? undefined}
allowDecimal={false}
size={mediaQuerySize}
size={isSmallScreen ? 'md' : 'xl'}
onChange={(e) => onPropertyYields(e as number)}
/>
<NumberInput
Expand All @@ -40,7 +40,7 @@ export function PropertyYields() {
min={propertyYields.min}
max={100}
allowDecimal={false}
size={mediaQuerySize}
size={isSmallScreen ? 'md' : 'xl'}
onChange={(e) => onPropertyYields(undefined, e as number)}
/>
</>
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/components/PropertyPanel/PropertyPanelActions.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useTranslation } from "react-i18next";
import Env from "../../utils/env";
import { ActionIcon, Button, Flex, Grid } from "@mantine/core";
import GoogleIcon from '@mui/icons-material/Google';
import XIcon from '@mui/icons-material/X';
import AlternateEmailIcon from '@mui/icons-material/AlternateEmail';
import { AffixBtn } from "../Common/AffixBtn";
import Env from "../../utils/env";
import { AffixBtn } from "../Common/AffixBtn/AffixBtn";
import { useCopyUrl } from "../../hooks/useCopyUrl";
import { useViewportSize } from "@mantine/hooks";
import { Property } from "../../types/property";
import { useSmallScreen } from "../../hooks/useSmallScreen";

function encodeUrlUsingPercentEncoding(url: string) {
return encodeURI(url);
Expand All @@ -24,7 +24,7 @@ export function PropertyPanelActions({
coordinates: Property['coordinates'];
onClose: () => void;
}) {
const { width } = useViewportSize();
const isSmallScreen = useSmallScreen();
const { t } = useTranslation('common');
const { copied, onCopyUrl } = useCopyUrl();

Expand Down Expand Up @@ -115,7 +115,7 @@ export function PropertyPanelActions({
</Button>
}>
<Button
fullWidth={width > 768}
fullWidth={isSmallScreen}
onClick={onClose}>
{t('actions.close')}
</Button>
Expand Down
108 changes: 0 additions & 108 deletions frontend/src/components/Settings/AppActions.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { useState, useRef } from "react";
import { Flex } from "@mantine/core";
import { CopyUrlAction } from "./CopyUrlAction";
import { HelpPanelAction } from "./HelpPanelAction";
import { FilteringPanelAction } from "./FilteringPanelAction";
import { SettingsPanelAction } from "./SettingsPanelAction";
import { WalletPanelAction } from "./WalletPanelAction";
import { SearchBar } from "../../SearchBar";
import { StartTooltip } from "../../StartTooltip";
import { SearchAction } from "./SearchAction";
import { useSmallScreen } from "../../../../hooks/useSmallScreen";

export function ActionsWrapper(props: {
onOpenWallets: () => void;
onOpenMapOptions: () => void;
onOpenFiltering: () => void;
onOpenHelp: () => void;
}) {
const isSmallScreen = useSmallScreen();
const [isSearchOpen, setIsSearchOpen] = useState(false);
const searchBarRef = useRef<{ focus: () => void }>(null);

const onToggleSearch = () => {
setIsSearchOpen((prev) => {
if (!prev) {
setTimeout(() => searchBarRef.current?.focus(), 0);
}
return !prev;
});
}

return (
<Flex
direction={isSmallScreen ? 'column' : 'row'}
align={isSmallScreen ? 'baseline' : 'end'}
gap="xs"
className="w-screen md:w-auto pt-2 md:pt-0">
{
isSmallScreen
? isSearchOpen && <SearchBar ref={searchBarRef} />
: <SearchBar ref={searchBarRef} />
}
{ isSmallScreen && <StartTooltip onClick={props.onOpenWallets} /> }
<Flex
className="w-full md:w-auto"
direction="row"
align="end"
justify={isSmallScreen ? 'space-around' : 'end'}
gap="xs">
<CopyUrlAction />
<WalletPanelAction onOpenWallets={props.onOpenWallets} />
<SettingsPanelAction onOpenMapOptions={props.onOpenMapOptions} />
<FilteringPanelAction onOpenFiltering={props.onOpenFiltering} />
<HelpPanelAction onOpenHelp={props.onOpenHelp} />
{
isSmallScreen && <SearchAction onToggleSearch={onToggleSearch} />
}
</Flex>
</Flex>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useTranslation } from "react-i18next";
import LinkIcon from '@mui/icons-material/Link';
import CheckIcon from '@mui/icons-material/Check';
import { AppActionsButton } from "../AppActionsButton";
import { useCopyUrl } from "../../../../hooks/useCopyUrl";

export function CopyUrlAction() {
const { t } = useTranslation('common');
const { copied, onCopyUrl } = useCopyUrl();

return (
<AppActionsButton opened={false} open={onCopyUrl} label={t('actions.copyUrl')} color={copied ? 'teal' : ''}>
{
!copied
? <LinkIcon fontSize="large" />
: <CheckIcon fontSize="large" />
}
</AppActionsButton>
)
}
Loading

0 comments on commit a3595d0

Please sign in to comment.