-
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.
* 필터 기능 추가 * 🐛 의존성 싱크 맞추기 * 🐛 충돌 해결 Co-authored-by: Yong <[email protected]> * ⚡️ 타입 좁히기 * ✨ 카테고리 필터링 API 연결 * ✨ 언어별 필터링을 위해 쿼리함수 수정 * ✨ 언어별 필터링 API 연결 * ✨ 선택된 언어 동작 스타일 적용 --------- Co-authored-by: Sang-minKIM <[email protected]> Co-authored-by: Yong <[email protected]>
- Loading branch information
1 parent
c738796
commit 7d54c71
Showing
13 changed files
with
126 additions
and
53 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,18 +1,34 @@ | ||
import { useRecoilValue } from "recoil"; | ||
import styled from "styled-components"; | ||
|
||
import { languageState } from "~/widgets/language-rank/model/language-rank.atom"; | ||
|
||
interface LanguageProps { | ||
language: string; | ||
onLanguageClick: () => void; | ||
id: number; | ||
} | ||
|
||
const Item = styled.div` | ||
const Item = styled.button` | ||
width: 100%; | ||
height: 21px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
gap: 16px; | ||
background-color: transparent; | ||
border: none; | ||
color: ${({ theme }) => theme.colors.secondary}; | ||
&.active { | ||
color: ${({ theme }) => theme.colors.white}; | ||
} | ||
`; | ||
|
||
export const Language = ({ language }: LanguageProps) => { | ||
return <Item>{language}</Item>; | ||
export const Language = ({ language, onLanguageClick, id }: LanguageProps) => { | ||
const activeLanguageId = useRecoilValue(languageState); | ||
return ( | ||
<Item onClick={onLanguageClick} className={activeLanguageId === id ? "active" : ""}> | ||
{language} | ||
</Item> | ||
); | ||
}; |
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 * from "./ui/question-list-filter.ui"; |
8 changes: 8 additions & 0 deletions
8
src/entities/question-list-filter/model/question-list-filter.atom.ts
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,8 @@ | ||
import { atom } from "recoil"; | ||
|
||
import { Category } from "./question-list-filter.type"; | ||
|
||
export const categoryState = atom<Category>({ | ||
key: "categoryState", | ||
default: "popular", | ||
}); |
1 change: 1 addition & 0 deletions
1
src/entities/question-list-filter/model/question-list-filter.type.ts
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 type Category = "popular" | "answered" | "not-answered" | "all"; |
58 changes: 58 additions & 0 deletions
58
src/entities/question-list-filter/ui/question-list-filter.ui.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,58 @@ | ||
import { useRecoilState } from "recoil"; | ||
import styled from "styled-components"; | ||
|
||
import { categoryState } from "../model/question-list-filter.atom"; | ||
import { Category } from "../model/question-list-filter.type"; | ||
|
||
const filterArr = [ | ||
{ | ||
uiName: "Popular questions", | ||
apiName: "popular", | ||
}, | ||
{ | ||
uiName: "Answered", | ||
apiName: "answered", | ||
}, | ||
{ | ||
uiName: "All questions", | ||
apiName: "all", | ||
}, | ||
{ | ||
uiName: "Wait to be answered", | ||
apiName: "not-answered", | ||
}, | ||
]; | ||
|
||
const Ul = styled.ul` | ||
display: flex; | ||
justify-content: center; | ||
gap: 50px; | ||
`; | ||
|
||
const Li = styled.li` | ||
color: ${(props) => props.theme.colors.tabBar}; | ||
cursor: pointer; | ||
&.active { | ||
color: ${(props) => props.theme.colors.white}; | ||
} | ||
`; | ||
|
||
export const QuestionListFilter = () => { | ||
const [category, setCategory] = useRecoilState(categoryState); | ||
|
||
return ( | ||
<Ul> | ||
{filterArr.map((item) => { | ||
return ( | ||
<Li | ||
key={item.uiName} | ||
className={category === item.apiName ? "active" : ""} | ||
onClick={() => setCategory(item.apiName as Category)} | ||
> | ||
{item.uiName} | ||
</Li> | ||
); | ||
})} | ||
</Ul> | ||
); | ||
}; |
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,14 +1,14 @@ | ||
import { ENV } from "~/shared/environment"; | ||
|
||
export const QUESTION_LIST_ENDPOINT = { | ||
default: `${ENV.baseUrl}/api/question/page/popular`, | ||
pagination: (body: { size: number; page: number }) => | ||
`${ENV.baseUrl}/api/question/page/popular?size=${body.size}&page=${body.page}`, | ||
// default: `${ENV.baseUrl}/api/question/page/popular`, | ||
pagination: (body: { category: string; size: number; page: number; language: number }) => | ||
`${ENV.baseUrl}/api/question/${body.category}?categories=${body.language || ""}&size=${body.size}&page=${body.page}`, | ||
}; | ||
|
||
export const QUESTION_LIST_KEY = { | ||
default: ["question-list"], | ||
pagination: (body: { size: number; page: number }) => { | ||
return [...QUESTION_LIST_KEY.default, body.size, body.page]; | ||
pagination: (body: { category: string; size: number; page: number; language: number }) => { | ||
return [...QUESTION_LIST_KEY.default, body.category, body.size, body.page, body.language]; | ||
}, | ||
}; |
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,6 @@ | ||
import { atom } from "recoil"; | ||
|
||
export const languageState = atom({ | ||
key: "languageState", | ||
default: 0, | ||
}); |
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