Skip to content

Commit

Permalink
feat : 클릭한 탭, 드롭다운 정보 sessionStorage 저장
Browse files Browse the repository at this point in the history
  • Loading branch information
f0rever0 committed Oct 27, 2023
1 parent 324554d commit db8cdfb
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 38 deletions.
3 changes: 2 additions & 1 deletion src/components/common/Select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface SelectProps<T extends LabelKeyType> {
baseValue: T;
baseLabel: string;
selectedValue: T;
setSelectedValue: React.Dispatch<React.SetStateAction<T>>;
setSelectedValue: (newValue: T) => void;
labels: Record<T, string>;
}

Expand All @@ -25,6 +25,7 @@ export default function Select<T extends LabelKeyType>({
const toggleSelect = () => setIsOpen(!isOpen);

const handleSelect = (value: T) => {
console.log(value);
setSelectedValue(value);
};

Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { getStorageHandler } from '@src/lib/utils/storageHandler';
export default function useStorage<T>(
key: string,
storageType: 'localStorage' | 'sessionStorage',
defaultValue?: T,
): [value: T | null, setValue: (newValue: T) => void] {
defaultValue: T,
): [value: T, setValue: (newValue: T) => void] {
const handler = getStorageHandler(storageType);
const [valueInState, setValueInState] = useState<T | null>(null);
const [valueInState, setValueInState] = useState<T>(defaultValue);

useEffect(() => {
const storageItem = handler.getItem<T>(key);
Expand Down
34 changes: 17 additions & 17 deletions src/lib/constants/tabs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExtraPart, Part, PartExtraType } from '@src/lib/types/universal';
import { PartCategoryType } from '@src/lib/types/blog';

export const activeGenerationCategoryList: number[] = [0];

Expand All @@ -14,22 +14,22 @@ for (let i = 31; i >= 24; i--) {
generationCategoryLabel[i] = `${i}기`;
}

export const activePartCategoryList: ExtraPart[] = [
PartExtraType.ALL,
Part.PLAN,
Part.DESIGN,
Part.ANDROID,
Part.IOS,
Part.WEB,
Part.SERVER,
export const activePartCategoryList: PartCategoryType[] = [
PartCategoryType.ALL,
PartCategoryType.PLAN,
PartCategoryType.DESIGN,
PartCategoryType.ANDROID,
PartCategoryType.IOS,
PartCategoryType.WEB,
PartCategoryType.SERVER,
];

export const partCategoryLabel: Record<ExtraPart, string> = {
[PartExtraType.ALL]: '파트',
[Part.PLAN]: '기획',
[Part.DESIGN]: '디자인',
[Part.ANDROID]: '안드로이드',
[Part.IOS]: 'iOS',
[Part.WEB]: '웹',
[Part.SERVER]: '서버',
export const partCategoryLabel: Record<PartCategoryType, string> = {
[PartCategoryType.ALL]: '파트',
[PartCategoryType.PLAN]: '기획',
[PartCategoryType.DESIGN]: '디자인',
[PartCategoryType.ANDROID]: '안드로이드',
[PartCategoryType.IOS]: 'iOS',
[PartCategoryType.WEB]: '웹',
[PartCategoryType.SERVER]: '서버',
};
10 changes: 10 additions & 0 deletions src/lib/types/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ export type BlogPostType = {
/* review */
subject?: string;
};

export enum PartCategoryType {
ALL = 'ALL',
PLAN = 'PLAN',
DESIGN = 'DESIGN',
ANDROID = 'ANDROID',
IOS = 'iOS',
WEB = 'WEB',
SERVER = 'SERVER',
}
8 changes: 6 additions & 2 deletions src/lib/types/review.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PartCategoryType } from '@src/lib/types/blog';
import { BlogPostType } from './blog';
import { ExtraPart } from './universal';

export type GetSampleReviewsResponse = {
reviews: BlogPostType[];
Expand All @@ -11,6 +11,10 @@ export type GetReviewsResponse = {
};

export interface ReviewAPI {
getResponse(majorTab: number, subTab: ExtraPart, page: number): Promise<GetReviewsResponse>;
getResponse(
majorTab: number,
subTab: PartCategoryType,
page: number,
): Promise<GetReviewsResponse>;
getSampleReviews(): Promise<GetSampleReviewsResponse>;
}
8 changes: 6 additions & 2 deletions src/lib/types/sopticle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PartCategoryType } from '@src/lib/types/blog';
import { BlogPostType } from './blog';
import { ExtraPart } from './universal';

export type GetSopticlesResponse = {
hasNextPage: boolean;
Expand All @@ -11,6 +11,10 @@ export type PostSopticleLikeResponse = {
likeChanged: boolean;
};
export interface SopticleAPI {
getResponse(majorTab: number, subTab: ExtraPart, page: number): Promise<GetSopticlesResponse>;
getResponse(
majorTab: number,
subTab: PartCategoryType,
page: number,
): Promise<GetSopticlesResponse>;
postSopticleLike(sopticleId: number, prevLike: boolean): Promise<PostSopticleLikeResponse>;
}
20 changes: 15 additions & 5 deletions src/views/BlogPage/BlogPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';
import PageLayout from '@src/components/common/PageLayout';
import useStorage from '@src/hooks/useStorage';
import { activeGenerationCategoryList } from '@src/lib/constants/tabs';
import { ExtraPart, PartExtraType } from '@src/lib/types/universal';
import { PartCategoryType } from '@src/lib/types/blog';
import { OvalSpinner } from '@src/views/ProjectPage/components';
import BlogPostList from './components/BlogPostList';
import BlogTab from './components/BlogTab';
Expand All @@ -10,11 +10,21 @@ import useFetch from './hooks/useFetch';
import * as S from './style';

export default function BlogPage() {
const [selectedTab, setSelectedTab] = useState<BlogTabType>(BlogTabType.REVIEW);
const [selectedMajorCategory, setMajorCategory] = useState<number>(
const [selectedTab, setSelectedTab] = useStorage(
'selectedTab',
'sessionStorage',
BlogTabType.REVIEW,
);
const [selectedMajorCategory, setMajorCategory] = useStorage(
'selectedMajorCategory',
'sessionStorage',
activeGenerationCategoryList[0],
);
const [selectedSubCategory, setSubCategory] = useState<ExtraPart>(PartExtraType.ALL);
const [selectedSubCategory, setSubCategory] = useStorage(
'selectedSubCategory',
'sessionStorage',
PartCategoryType.ALL,
);

const {
state: response,
Expand Down
12 changes: 6 additions & 6 deletions src/views/BlogPage/components/BlogTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import {
generationCategoryLabel,
partCategoryLabel,
} from '@src/lib/constants/tabs';
import { ExtraPart, PartExtraType } from '@src/lib/types/universal';
import { PartCategoryType } from '@src/lib/types/blog';
import * as S from './style';
import { BlogTabMap, BlogTabType } from './types';

interface BlogTanProps {
selectedTab: BlogTabType;
setSelectedTab: React.Dispatch<React.SetStateAction<BlogTabType>>;
setSelectedTab: (newValue: BlogTabType) => void;
selectedMajorCategory: number;
setMajorCategory: React.Dispatch<React.SetStateAction<number>>;
selectedSubCategory: ExtraPart;
setSubCategory: React.Dispatch<React.SetStateAction<ExtraPart>>;
setMajorCategory: (newValue: number) => void;
selectedSubCategory: PartCategoryType;
setSubCategory: (newValue: PartCategoryType) => void;
}
export default function BlogTab({
selectedTab,
Expand Down Expand Up @@ -72,7 +72,7 @@ export default function BlogTab({
baseLabel="파트"
selectedValue={selectedSubCategory}
setSelectedValue={setSubCategory}
baseValue={PartExtraType.ALL}
baseValue={PartCategoryType.ALL}
/>
</S.SlectContainer>
</S.Container>
Expand Down
4 changes: 2 additions & 2 deletions src/views/BlogPage/hooks/useFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { useCallback, useEffect } from 'react';
import useBooleanState from '@src/hooks/useBooleanState';
import useStackedFetchBase from '@src/hooks/useStackedFetchBase';
import { api } from '@src/lib/api';
import { ExtraPart } from '@src/lib/types/universal';
import { PartCategoryType } from '@src/lib/types/blog';
import { BlogTabType } from '../components/BlogTab/types';
import useInfiniteScroll from './useInfiniteScroll';

interface useFetchProps {
selectedTab: BlogTabType;
selectedMajorCategory: number;
selectedSubCategory: ExtraPart;
selectedSubCategory: PartCategoryType;
}

const useFetch = ({
Expand Down

0 comments on commit db8cdfb

Please sign in to comment.