Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/Community_list/#92' into Communi…
Browse files Browse the repository at this point in the history
…ty_list/#92
  • Loading branch information
Brokyeom committed Jul 19, 2022
2 parents 008ae70 + c352c79 commit 9c607ef
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
3 changes: 2 additions & 1 deletion core/api/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import { baseInstance } from '../axios';
// };

export const useGetCommunityList = () => {
const { data, error } = useSWR('/board', baseInstance.get, {
const { data, error } = useSWR(`/board`, baseInstance.get, {
errorRetryCount: 3,
});
console.log(data);

return {
communityList: data,
Expand Down
52 changes: 30 additions & 22 deletions pages/community/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,39 @@ import { useGetCommunityList } from '../../core/api/community';
const limit = 10;

export default function community() {
const [isLoading, setIsLoading] = useState<boolean>(false);
const [contentList, setContentList] = useState<CommunityData[]>([]);
const [currentPage, setCurrentPage] = useState<number>(1);

const handleCurrentPage = (nextPage: number) => {
setCurrentPage(nextPage);
};
let { communityList, isLoading, isError } =
useGetCommunityList() as GetCommunityList;
const data = useGetCommunityList();
console.log(data.communityList);

useEffect(() => {
console.log(communityList);
if (communityList) {
let data = communityList.data as CommunityData[];
data = data.filter(
(_, idx) => (currentPage - 1) * 10 <= idx && idx < currentPage * 10,
);
console.log(data);
setContentList(data);
window.scrollTo({
top: 0,
behavior: 'smooth',
});
}
}, [contentList, currentPage]);
console.log(contentList);
setIsLoading(true);
setIsLoading(false);
});

// const handleCurrentPage = (nextPage: number) => {
// setCurrentPage(nextPage);
// };
// let { communityList, isLoading, isError } =
// useGetCommunityList() as GetCommunityList;

// useEffect(() => {
// if (communityList) {
// let data = communityList as CommunityData[];
// data = data.filter(
// (_, idx) => (currentPage - 1) * 10 <= idx && idx < currentPage * 10,
// );
// setContentList(data);
// console.log(data);
// window.scrollTo({
// top: 0,
// behavior: 'smooth',
// });
// }
// }, [contentList, currentPage]);
// console.log(contentList);
// setIsLoading(true);
// fetch('/board')
// .then((res) => res.json())
Expand Down Expand Up @@ -73,13 +81,13 @@ export default function community() {
</StContentBlock>
<CommunityFloatingBtn />
</StMainArticle>
{!isLoading && !isError && communityList && (
{/* {!isLoading && !isError && communityList && (
<PageNavigation
currentPage={currentPage}
lastPage={Math.ceil(contentList.length / limit)}
handleCurrentPage={handleCurrentPage}
/>
)}
)} */}
</>
)}
</StCommunityWrapper>
Expand Down
2 changes: 1 addition & 1 deletion types/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface PostCommentBody {
}

export interface GetCommunityList {
communityList: { data: CommunityData[] };
communityList: CommunityData[];
isLoading: boolean;
isError: string;
}

0 comments on commit 9c607ef

Please sign in to comment.