Skip to content

Commit

Permalink
switch toggle filter ์ ์šฉ
Browse files Browse the repository at this point in the history
ํ˜„์žฌ ๋ฐ์ดํ„ฐ ๊ธฐ์ค€(๋ธŒ๋ฆฌ๋” 14๋ช…, ์ธ์ฆ 2๋ช…) 2page์—์„œ ํ† ๊ธ€์„ on ํ•  ๊ฒฝ์šฐ 2page์— ํ•ด๋‹นํ•˜๋Š” data๊ฐ€ ์—†์–ด์„œ ์˜ค๋ฅ˜ ๋‚จ.
  • Loading branch information
bkks1004 committed Sep 12, 2023
1 parent 73b851c commit c610212
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
17 changes: 9 additions & 8 deletions src/components/common/toggle/Switch.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, ChangeEvent } from 'react';
import React from 'react';
import { styled } from 'styled-components';

const StyledLabel = styled.label<{ checked: boolean }>`
Expand All @@ -25,14 +25,15 @@ const StyledLabel = styled.label<{ checked: boolean }>`
}
`;

const Switch = () => {
const [switchState, setSwitchState] = useState(true);
function handleOnChange(e: ChangeEvent<HTMLInputElement>) {
setSwitchState(!switchState);
}
interface Props {
checked: boolean;
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
}

const Switch = ({ checked, onChange }: Props) => {
return (
<StyledLabel htmlFor="checkbox" checked={switchState}>
<input id="checkbox" type="checkbox" checked={switchState} onChange={handleOnChange} />
<StyledLabel htmlFor="checkbox" checked={checked}>
<input id="checkbox" type="checkbox" checked={checked} onChange={onChange} />
</StyledLabel>
);
};
Expand Down
16 changes: 10 additions & 6 deletions src/pages/mypage/breeders/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,23 @@ const Title = styled.p`
export default function Breeders() {
const SIZE = 8 as const;
const [page, setPage] = useState(1);
const [verification, setVerification] = useState(true);
const [breeders, setBreeders] = useState<IBreeder[]>([]);
const [pageInfo, setPageInfo] = useState<Page>({
totalPages: 0,
first: false,
last: false,
number: 0,
});

const fetchBreeders = async ({ keyword = '', page = 0 }) => {
const fetchBreeders = async ({ keyword = '', page = 0, verification = true }) => {
try {
const { data: res } = await axios.get<AxiosResponse<Pageable<IBreeder[]>>>('/breeders', {
params: {
page,
keyword,
size: SIZE,
sort: 'string',
verification: verification ? 'yes' : '',
},
});

Expand All @@ -80,18 +81,21 @@ export default function Breeders() {
};

const onSearch = async (keyword: string) => {
fetchBreeders({ keyword });
fetchBreeders({ keyword, verification });
};
const handleSwitchChange = () => {
setVerification(!verification);
};

useEffect(() => {
fetchBreeders({ page: page - 1 });
}, [page]);
fetchBreeders({ page: page - 1, verification });
}, [page, verification]);

return (
<Layout style={{ marginTop: '10rem' }}>
<Title>๋ธŒ๋ฆฌ๋” ๋ชจ์•„๋ณด๊ธฐ</Title>
<div style={{ display: 'flex' }}>
<Switch />
<Switch checked={verification} onChange={handleSwitchChange} />
<Text>์ธ์ฆ ๋ธŒ๋ฆฌ๋”๋งŒ ๋ณด๊ธฐ</Text>
<SearchInput placeholder="์›ํ•˜์‹œ๋Š” ๊ฒฌ์ข…์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”." onSearch={onSearch} />
</div>
Expand Down

0 comments on commit c610212

Please sign in to comment.