Skip to content

Commit bdf417b

Browse files
committed
[feat]뒤로가기 필터링 유지
1 parent e320cc8 commit bdf417b

File tree

5 files changed

+39
-19
lines changed

5 files changed

+39
-19
lines changed

src/domains/recipe/components/details/BackBtn.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
'use client';
22

3-
import { useSearchParams } from 'next/navigation';
4-
import Link from 'next/link';
3+
import { useRouter } from 'next/navigation';
54
import Back from '@/shared/assets/icons/back_36.svg';
65

76
function BackButton() {
8-
const searchParams = useSearchParams();
9-
const recipeUrl = `/recipe${searchParams.toString() ? `?${searchParams.toString()}` : ''}`;
7+
const router = useRouter()
8+
9+
10+
const handleClick = () => {
11+
const url = sessionStorage.getItem('saveUrl')
12+
if(!url) return
13+
router.push(url)
14+
}
1015

11-
// 쿼리스트링을 유지한채 뒤로 돌아가야함
1216

1317
return (
14-
<button type="button" className="z-1" aria-label="뒤로가기">
15-
<Link href={recipeUrl}>
16-
<Back />
17-
</Link>
18+
<button type="button" className="z-1" aria-label="뒤로가기" onClick={ handleClick}>
19+
<Back />
1820
</button>
1921
);
2022
}

src/domains/recipe/components/main/Accordion.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,10 @@ function Accordion({ setAlcoholBaseTypes, setCocktailTypes, setAlcoholStrengths
133133
const queryString = params.toString();
134134
const newUrl = `${pathname}${queryString ? `?${queryString}` : ''}`;
135135

136+
137+
router.push(newUrl)
136138
// shallow routing으로 URL만 변경
137-
window.history.pushState({ ...window.history.state, as: newUrl, url: newUrl }, '', newUrl);
139+
// window.history.pushState({ ...window.history.state, as: newUrl, url: newUrl }, '', newUrl);
138140
};
139141

140142
return (

src/domains/recipe/components/main/CocktailList.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,26 @@ function CocktailList({ cocktails, RecipeFetch, hasNextPage, lastId, onItemClick
2626

2727
useIntersectionObserver(cocktailRef, onIntersect, hasNextPage);
2828

29+
const handleClick = () => {
30+
sessionStorage.setItem('listScrollY', String(window.scrollY));
31+
sessionStorage.setItem('saveUrl', String(location.href))
32+
}
33+
2934
return (
3035
<ul
31-
className="place-content-between
36+
className="place-content-between
3237
grid gap-8 justify-items-center
3338
grid-cols-1 sm:justify-items-stretch
34-
sm:[grid-template-columns:repeat(2,minmax(0,320px))] sm:gap-8 md:[grid-template-columns:repeat(3,minmax(0,250px))]
35-
lg:[grid-template-columns:repeat(4,minmax(0,250px))]
39+
sm:[grid-template-columns:repeat(2,minmax(0,1fr))] sm:gap-8 md:[grid-template-columns:repeat(3,minmax(0,1fr))]
40+
lg:[grid-template-columns:repeat(4,minmax(0,1fr))]
3641
"
3742
>
3843
{cocktails.map(
3944
({ cocktailImgUrl, cocktailId, cocktailName, cocktailNameKo, alcoholStrength }) => (
4045
<li key={cocktailId} onClick={onItemClick}>
4146
<Link
4247
href={`/recipe/${cocktailId}`}
43-
onClick={() => {
44-
sessionStorage.setItem('listScrollY', String(window.scrollY));
45-
}}
48+
onClick={handleClick}
4649
>
4750
<CocktailCard
4851
id={cocktailId}

src/domains/shared/components/cocktail-card/CocktailCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function CocktailCard({
3636
<div className="flex flex-col gap-4">
3737
<div
3838
className={tw(
39-
`${!className && 'w-80 h-75 md:w-62.5 '} rounded-xl overflow-hidden relative`,
39+
`${!className && 'w-80 h-75 md:max-w-62.5 '} rounded-xl overflow-hidden relative`,
4040
className
4141
)}
4242
>

src/domains/shared/components/keep/Keep.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import KeepIcon from '@/shared/assets/icons/keep_36.svg';
44
import KeepIconActive from '@/shared/assets/icons/keep_active_36.svg';
5-
import { useState } from 'react';
6-
import { deleteKeep, postKeep } from '../../api/keep/keep';
5+
import { useEffect, useState } from 'react';
6+
import { deleteKeep, postKeep } from '../../api/keep/keep';
7+
import { getApi } from '@/app/api/config/appConfig';
78

89
interface Props {
910
className?: string;
@@ -14,6 +15,18 @@ interface Props {
1415

1516
function Keep({ className, cocktailId }: Props) {
1617
const [isClick, setIsClick] = useState(false);
18+
19+
useEffect(() => {
20+
const getKeep = async () => {
21+
const res = await fetch(`${getApi}/me/bar`, {
22+
credentials:'include'
23+
})
24+
const json = await res.json()
25+
json.data.items.keptAt ? setIsClick(true) : setIsClick(false)
26+
}
27+
getKeep()
28+
},[])
29+
1730
const handleClick = async (e: React.MouseEvent<HTMLButtonElement>) => {
1831
e.preventDefault();
1932
e.stopPropagation();

0 commit comments

Comments
 (0)