Skip to content

Commit

Permalink
Merge pull request #73 from delicious-algorithme/main
Browse files Browse the repository at this point in the history
Main
  • Loading branch information
Songhyejeong authored Nov 16, 2024
2 parents 96d5514 + fb6e887 commit c8dca78
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/components/common/bookmark/BookmarkContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { deleteBookmarkStore, postBookmarkStore } from '../../../apis/api/bookma
import { useNavigate } from 'react-router-dom';
import styled from 'styled-components';
import { useSaveBookmarkId } from '../../../store';
import { useState } from 'react';

const BookmarkContainer = ({ bookmarkId, storeId }) => {
const { savedId } = useSaveBookmarkId();

const auth = JSON.parse(localStorage.getItem('auth')) || {};
const isSaved = savedId.includes(bookmarkId) && auth.state.isLoggedIn;

const [isSaved, setIsSaved] = useState(savedId.includes(bookmarkId) && auth.state.isLoggedIn);
const navigate = useNavigate();

const handleClickBookmarks = async (e) => {
Expand All @@ -24,11 +24,12 @@ const BookmarkContainer = ({ bookmarkId, storeId }) => {
const response = await deleteBookmarkStore(bookmarkId);
if (response.status === 204) {
console.log('success delete');
setIsSaved(false);
}
} else {
const response = await postBookmarkStore(storeId);
if (response.status === 201) {
navigate('/bookmark');
setIsSaved(true);
} else {
console.log(response.error);
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/common/store/StoreCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const StoreListCard = ({ image, alt, id, name, address, rating, positiveRatio, p
const navigate = useNavigate();
const { savedStores } = useSaveBookmarkId();

const bookmarkId = savedStores.filter((store) => store.storeResponseDto.storeId === id).bookmarkId;
const bookmark = savedStores.find((store) => store.storeResponseDto.storeId === id);
const bookmarkId = bookmark?.bookmarkId;

const cardClickHandler = () => {
navigate(`/webmap/storeDetail/${id}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ import { useNavigate } from 'react-router-dom';
import { Orange, Grey, DarkGrey } from '../../color';
import Bookmark from '../common/bookmark/BookmarkContainer';
import { useSaveBookmarkId } from '../../store';
import { useState } from 'react';
import { useEffect, useState } from 'react';

const TopStoreCard = ({ image, alt, bookmarkId, id, address, name, positiveRatio, keyword }) => {
const navigate = useNavigate();
const { savedStores } = useSaveBookmarkId();
const [savedId, setSavedId] = useState(bookmarkId ? bookmarkId : null);

if (!bookmarkId) {
const bookmarkId = savedStores.filter((store) => store.storeResponseDto.storeId === id);
setSavedId(bookmarkId);
}
useEffect(() => {
if (!bookmarkId) {
const bookmark = savedStores.find((store) => store.storeResponseDto.storeId === id);
const bookmarkId = bookmark?.bookmarkId;
setSavedId(bookmarkId);
}
// eslint-disable-next-line
}, []);

const cardClickHandler = (id) => {
navigate(`/webmap/storeDetail/${id}`, { state: { detailVisible: true } });
Expand Down
2 changes: 1 addition & 1 deletion src/components/storeCard/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import TopStoreCard from './StoreCard';
import TopStoreCard from './TopStoreCard';

export { TopStoreCard };

0 comments on commit c8dca78

Please sign in to comment.