Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: 클라이언트 필터링 컴포넌트를 개선한다 #569

Merged
merged 5 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions frontend/src/components/ui/ClientStationFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { styled } from 'styled-components';

import { useExternalState } from '@utils/external-state';
import { useExternalState, useExternalValue } from '@utils/external-state';

import { navigationBarPanelStore } from '@stores/layout/navigationBarPanelStore';
import { clientStationFiltersStore } from '@stores/station-filters/clientStationFiltersStore';

import ButtonNext from '@common/ButtonNext';

import { NAVIGATOR_PANEL_WIDTH } from '@constants';
import { CHARGING_SPEED } from '@constants/chargers';

const ClientStationFilters = () => {
Expand All @@ -19,6 +21,12 @@ const ClientStationFilters = () => {
setFilterOption,
] = useExternalState(clientStationFiltersStore);

const { basePanel, lastPanel } = useExternalValue(navigationBarPanelStore);
const navigationComponentWidth =
(basePanel === null ? 0 : NAVIGATOR_PANEL_WIDTH) +
(lastPanel === null ? 0 : NAVIGATOR_PANEL_WIDTH) +
10;

const toggleAvailableStation = () => {
setFilterOption((prev) => ({
...prev,
Expand Down Expand Up @@ -48,7 +56,7 @@ const ClientStationFilters = () => {
};

return (
<Container>
<Container left={navigationComponentWidth}>
<ButtonNext
onClick={toggleAvailableStation}
variant={isAvailableStationFilterSelected ? 'contained' : 'outlined'}
Expand Down Expand Up @@ -85,10 +93,10 @@ const ClientStationFilters = () => {
);
};

const Container = styled.div`
const Container = styled.div<{ left: number }>`
position: fixed;
top: 10px;
left: 180px;
left: ${(props) => props.left}rem;
z-index: 998;
padding: 10px;
background-color: white;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ArrowLeftIcon, ArrowPathIcon } from '@heroicons/react/24/outline';
import { css } from 'styled-components';

import { memberTokenStore } from '@stores/login/memberTokenStore';
import { serverStationFilterAction } from '@stores/station-filters/serverStationFiltersStore';

import { useServerStationFilters } from '@hooks/tanstack-query/station-filters/useServerStationFilters';
import { useServerStationFilterStoreActions } from '@hooks/useServerStationFilterActions';
Expand All @@ -15,6 +14,7 @@ import Text from '@common/Text';
import ServerStationFiltersSkeleton from '@ui/ServerStationFilters/ServerStationFiltersSkeleton';
import { useNavigationBar } from '@ui/compound/NavigationBar/hooks/useNavigationBar';

import { NAVIGATOR_PANEL_WIDTH } from '@constants';
import { CONNECTOR_TYPES, COMPANIES } from '@constants/chargers';

import type { Capacity } from '@type';
Expand Down Expand Up @@ -55,7 +55,7 @@ const ServerStationFilters = () => {

return (
<FlexBox
width={34}
width={NAVIGATOR_PANEL_WIDTH}
height={'100vh'}
alignItems={'center'}
direction={'column'}
Expand All @@ -65,7 +65,7 @@ const ServerStationFilters = () => {
noRadius={'all'}
>
<FlexBox
width={34}
width={NAVIGATOR_PANEL_WIDTH}
height={8}
justifyContent="between"
alignItems="center"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import StationReportButton from '@ui/StationDetailsWindow/reports/station/Statio
import ReviewPreview from '@ui/StationDetailsWindow/reviews/previews/ReviewPreview';
import StationInformation from '@ui/StationDetailsWindow/station/StationInformation';

import { NAVIGATOR_PANEL_WIDTH } from '@constants';

import type { StationDetails } from '@type';

import CongestionStatistics from './congestion/CongestionStatistics';
Expand Down Expand Up @@ -35,7 +37,7 @@ const StationDetailsView = ({ station }: StationDetailsViewProps) => {
};

export const stationDetailsViewContainerCss = css`
width: 34rem;
width: ${NAVIGATOR_PANEL_WIDTH}rem;
height: 100vh;
background-color: white;
box-shadow: 1px 1px 2px gray;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { css } from 'styled-components';

import { useExternalValue } from '@utils/external-state';

import { selectedStationIdStore } from '@stores/selectedStationStore';

import { useStationDetails } from '@hooks/tanstack-query/station-details/useStationDetails';

import Box from '@common/Box';
Expand All @@ -8,6 +12,8 @@ import StationDetailsView from '@ui/StationDetailsWindow/StationDetailsView';
import StationDetailsViewSkeleton from '@ui/StationDetailsWindow/StationDetailsViewSkeleton';
import { useNavigationBar } from '@ui/compound/NavigationBar/hooks/useNavigationBar';

import { NAVIGATOR_PANEL_WIDTH } from '@constants';

const StationDetailsWindow = () => {
const {
data: selectedStation,
Expand All @@ -16,8 +22,9 @@ const StationDetailsWindow = () => {
isFetching,
} = useStationDetails();
const { handleClosePanel } = useNavigationBar();
const selectedStationId = useExternalValue(selectedStationIdStore);

if (!isFetching && selectedStation === undefined) {
if (selectedStationId === null || (!isFetching && selectedStation === null)) {
handleClosePanel();
}

Expand All @@ -37,7 +44,7 @@ const StationDetailsWindow = () => {
};

const stationDetailsWindowCss = css`
width: 34rem;
width: ${NAVIGATOR_PANEL_WIDTH}rem;
height: 100vh;
z-index: 999;
overflow: scroll;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Text from '@common/Text';

import StationList from '@ui/StationList/StationList';

import { NAVIGATOR_PANEL_WIDTH } from '@constants';

import StationSearchBar from './StationSearchBar';

const StationSearchWindow = () => {
Expand All @@ -23,7 +25,7 @@ const StationSearchWindow = () => {

const S = {
Container: styled.article`
width: 34rem;
width: ${NAVIGATOR_PANEL_WIDTH}rem;
height: 100vh;
background: #fcfcfc;
outline: 1.5px solid #e1e4eb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@ import Button from '@common/Button';
import { useNavigationBar } from './hooks/useNavigationBar';

interface Props {
canDisplay: boolean
canDisplay: boolean;
}

const CloseButton = ({ canDisplay }: Props) => {
const { handleClosePanel } = useNavigationBar();

if(!canDisplay) {
return <></>
if (!canDisplay) {
return <></>;
}

return (
<Button variant="label" aria-label="검색창 닫기" onClick={handleClosePanel}>
<Button
css={{ top: '50%', transform: 'translate(0, -50%);' }}
variant="label"
aria-label="검색창 닫기"
onClick={handleClosePanel}
>
<ChevronLeftIcon width="2.4rem" stroke="#9c9fa7" />
</Button>
);
Expand Down
27 changes: 1 addition & 26 deletions frontend/src/components/ui/compound/NavigationBar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import { css } from 'styled-components';

import type { PropsWithChildren } from 'react';
import { useEffect, useRef } from 'react';

import { useExternalValue, useSetExternalState } from '@utils/external-state';

import {
browserWidthStore,
navigatorAccordionWidthStore,
} from '@stores/layout/componentWidthStore';
import { navigationBarPanelStore } from '@stores/layout/navigationBarPanelStore';

import FlexBox from '@common/FlexBox';

Expand All @@ -21,24 +12,8 @@ import Menu from './Menu';
export type BasePanelType = 'searchWindow' | 'stationList' | 'serverStationFilters' | null;

const NavigationBar = ({ children }: PropsWithChildren) => {
const accordionContainerRef = useRef(null);

const { basePanel, lastPanel } = useExternalValue(navigationBarPanelStore);
const setNavigatorAccordionWidth = useSetExternalState(navigatorAccordionWidthStore);
const setBrowserWidth = useSetExternalState(browserWidthStore);

useEffect(() => {
setNavigatorAccordionWidth(accordionContainerRef.current.offsetWidth);
setBrowserWidth((prev) => {
if (prev === null) {
return document.body.offsetWidth;
}
return prev;
});
}, [basePanel, lastPanel]);

return (
<FlexBox gap={0} nowrap css={accordionContainerCss} ref={accordionContainerRef}>
<FlexBox gap={0} nowrap css={accordionContainerCss}>
{children}
</FlexBox>
);
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ export const FORM_PRIVATE_REASON_LENGTH_LIMIT = 100;

export const MIN_REVIEW_CONTENT_LENGTH = 10;
export const MAX_REVIEW_CONTENT_LENGTH = 100;

export const BROWSER_WIDTH = document.body.offsetWidth;
export const NAVIGATOR_PANEL_WIDTH = 34;
24 changes: 0 additions & 24 deletions frontend/src/hooks/google-maps/useCalculatedMapDelta.ts

This file was deleted.

5 changes: 2 additions & 3 deletions frontend/src/hooks/google-maps/useStationSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useExternalValue, useSetExternalState } from '@utils/external-state';
import { getCalculatedMapDelta } from '@utils/google-maps/getCalculatedMapDelta';

import { getGoogleMapStore } from '@stores/google-maps/googleMapStore';
import { markerInstanceStore } from '@stores/google-maps/markerInstanceStore';
Expand All @@ -9,13 +10,10 @@ import StationSummaryWindow from '@ui/StationSummaryWindow';

import type { StationSummary } from '@type';

import { useCalculatedMapDelta } from './useCalculatedMapDelta';

export const useStationSummary = () => {
const googleMap = useExternalValue(getGoogleMapStore());
const infoWindowInstance = useExternalValue(getStationSummaryWindowStore());
const stationMarkers = useExternalValue(markerInstanceStore);
const calculatedMapDelta = useCalculatedMapDelta();
const setSelectedStationId = useSetExternalState(selectedStationIdStore);

const openStationSummary = (
Expand All @@ -28,6 +26,7 @@ export const useStationSummary = () => {
);
const markerInstance = stationMarkerInstance ?? stationMarker.markerInstance;
const { lat, lng } = markerInstance.position as google.maps.LatLngLiteral;
const calculatedMapDelta = getCalculatedMapDelta();

setSelectedStationId(stationId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ export const fetchStationDetails = async (selectedStationId: string) => {

const data: StationDetails = await response.json();
return data;
// const changedDataList = Object.entries(data).map(([key, value]) => {
// if (INVALID_VALUE_LIST.includes(String(value))) {
// return [key, null];
// }
//
// return [key, value];
// });
//
// return Object.fromEntries(changedDataList);
});

return stationDetails;
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/stores/layout/componentWidthStore.ts

This file was deleted.

28 changes: 28 additions & 0 deletions frontend/src/utils/google-maps/getCalculatedMapDelta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { getGoogleMapStore } from '@stores/google-maps/googleMapStore';
import { navigationBarPanelStore } from '@stores/layout/navigationBarPanelStore';

import { BROWSER_WIDTH, NAVIGATOR_PANEL_WIDTH } from '@constants';

import { getDisplayPosition } from '.';

export const getCalculatedMapDelta = () => {
const navigationComponentWidth = getNavigationComponentWidth();
const browserWidth = BROWSER_WIDTH;
const googleMap = getGoogleMapStore().getState();

const navigatorAccordionWidthRatio = (navigationComponentWidth * 10) / browserWidth;
const calculatedMapDelta =
getDisplayPosition(googleMap).longitudeDelta * 2 * navigatorAccordionWidthRatio;

return calculatedMapDelta;
};

export const getNavigationComponentWidth = () => {
const { basePanel, lastPanel } = navigationBarPanelStore.getState();
const navigationComponentWidth =
(basePanel === null ? 0 : NAVIGATOR_PANEL_WIDTH) +
(lastPanel === null ? 0 : NAVIGATOR_PANEL_WIDTH) +
10;

return navigationComponentWidth;
};
Loading