Skip to content

Commit

Permalink
refactor : api component에서 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
lodado committed Mar 17, 2022
1 parent 9501293 commit 573bafb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
15 changes: 2 additions & 13 deletions frontend/src/components/organisms/WorkspaceListContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
import React from 'react';
import { useRecoilValue } from 'recoil';
import { useHistory } from 'react-router-dom';
import axios from 'axios';
import LabeledDefaultButton from '@atoms/LabeledDefaultButton';
import AsyncBranch from '@molecules/AsyncBranch';
import API from '@global/api';
import useInfinityScroll from '@hook/useInfinityPage';
import wavingHandImage from '@global/image/wavingHandFromSlack.gif';
import userState from '@state/user';
import { Workspace } from '@global/type';
import { queryFlatMap } from '@global/util/reactQueryUtil';
import { getWorkspaceLists } from '@global/api/workspace';
import {
HelloLabel,
StyledLabel,
Expand All @@ -32,7 +31,7 @@ const WorkSpaceLists = (workspaces: Workspace[]) => {
return workspaces.map(
({ id, name, count, fileId }: Workspace & { count: number }) => {
return (
<StyledDiv key={`workspacelist${id}`}>
<StyledDiv key={`${id}`}>
<StyledSelectWorkspace
firstLabelContent={name}
content={count}
Expand All @@ -50,16 +49,6 @@ const WorkSpaceLists = (workspaces: Workspace[]) => {
);
};

async function getWorkspaceLists({ pageParam = 0 }) {
const { data } = await axios.get(API.get.workspace.user, {
params: {
page: pageParam,
},
});

return data;
}

const WorkspaceList = () => {
const { data, fetchNextPage, hasNextPage, isFetchingNextPage } =
useInfinityScroll('workspacelists', getWorkspaceLists);
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/global/api/workspace/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ export const getUserHasWorkspace = async (

return res.data.userHasWorkspace;
};

export const getWorkspaceLists = async ({ pageParam = 0 }) => {
const { data } = await axios.get(API.get.workspace.user, {
params: {
page: pageParam,
},
});

return data;
};

0 comments on commit 573bafb

Please sign in to comment.