-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
129 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
components/main/mainFavoriteCardList/MainFavoriteCardList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Coin } from "../../../types/common/common.type"; | ||
import { MainFavCardListContainer } from "./style"; | ||
|
||
type Props = { | ||
data: Coin[] | null; | ||
}; | ||
|
||
const MainFavoriteCardList = () => { | ||
return <MainFavCardListContainer></MainFavCardListContainer>; | ||
}; | ||
|
||
export default MainFavoriteCardList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import styled from "styled-components"; | ||
|
||
export const MainFavCardListContainer = styled.div` | ||
width: 516px; | ||
display: flex; | ||
flex-wrap: wrap; | ||
column-gap: 20px; | ||
row-gap: 20px; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import styled from "styled-components"; | ||
|
||
export const MainContainer = styled.div` | ||
background-color: ${({ theme }) => theme.backgroundColor}; | ||
display: flex; | ||
justify-content: space-between; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const LOCAL_FAVORITES_KEY = "favorites" as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Dispatch, SetStateAction, useEffect, useState } from "react"; | ||
import { useRecoilState } from "recoil"; | ||
import { LOCAL_FAVORITES_KEY } from "../../constants/localStorage.contants"; | ||
import { mainFavoriteAtom } from "../../store/main/main.store"; | ||
import local from "../../util/local"; | ||
|
||
type Props = { | ||
pick: boolean; | ||
setPick: Dispatch<SetStateAction<boolean>>; | ||
}; | ||
|
||
const useFavorites = ({ pick, setPick }: Props) => { | ||
const [favorites, setFavorites] = useRecoilState(mainFavoriteAtom); | ||
|
||
const handlePick = (coinid: string) => { | ||
handleFavorites(coinid, pick); | ||
setPick((prev) => !prev); | ||
}; | ||
|
||
const handleFavorites = (coinid: string, pick: boolean) => { | ||
const copyFav = favorites; | ||
|
||
if (!pick) { | ||
const isOverlap = favorites.find((prev) => prev === coinid); | ||
|
||
if (isOverlap !== undefined) { | ||
return; | ||
} | ||
|
||
const addFav = copyFav.concat(coinid); | ||
|
||
setFavorites(addFav); | ||
local.set(LOCAL_FAVORITES_KEY, JSON.stringify(addFav)); | ||
} else { | ||
const removeFav = copyFav.filter((prev) => prev !== coinid); | ||
setFavorites(removeFav); | ||
local.set(LOCAL_FAVORITES_KEY, JSON.stringify(removeFav)); | ||
} | ||
}; | ||
|
||
return { | ||
pick, | ||
handlePick, | ||
}; | ||
}; | ||
|
||
export default useFavorites; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { atom } from "recoil"; | ||
import { LOCAL_FAVORITES_KEY } from "../../constants/localStorage.contants"; | ||
import local from "../../util/local"; | ||
|
||
export const mainFavoriteAtom = atom<string[]>({ | ||
key: "mainFavoriteAtom", | ||
default: | ||
local.get(LOCAL_FAVORITES_KEY) === null | ||
? [] | ||
: JSON.parse(local.get(LOCAL_FAVORITES_KEY) as string), | ||
}); |