Skip to content

Commit

Permalink
fix: loading
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoung-jnn committed Apr 6, 2024
1 parent 405d54c commit ce71f52
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 43 deletions.
9 changes: 7 additions & 2 deletions src/components/HomeSwiper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@ const HomeSwiper = () => {
const [data, setData] = useState<GetDaybookResponse[]>([]);
const [currentIndex, setCurrentIndex] = useState<number>(0);

const [isLoading, setIsLoading] = useState(false);

useEffect(() => {
(async () => {
setIsLoading(true);

const { data } = await getRandomDaybooks();
setData(data);

setIsLoading(false);
})();
}, []);

if (!data?.length) return <LoadingSpinner />;

return (
<>
{isLoading && <LoadingSpinner />}
<Swiper
css={css`
margin-top: 30px;
Expand Down
9 changes: 7 additions & 2 deletions src/components/MyWritingSwiper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@ const MyWritingSwiper = () => {
const [data, setData] = useState<GetDaybookResponse[]>([]);
const [currentIndex, setCurrentIndex] = useState<number>(0);

const [isLoading, setIsLoading] = useState(false);

useEffect(() => {
(async () => {
setIsLoading(true);

const { data } = await getDaybookList();
setData(data);

setIsLoading(false);
})();
}, []);

if (!data?.length) return <LoadingSpinner />;

return (
<>
{isLoading && <LoadingSpinner />}
<Swiper
css={css`
margin-top: 30px;
Expand Down
75 changes: 40 additions & 35 deletions src/components/OthersDayBook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,56 @@ import { getDaybook } from "@api";
import LoadingSpinner from "./LoadingSpinner";

const OthersWriting = () => {
const { id } = useParams();

const { id } = useParams();
const [daybookData, setDaybookData] = useState<GetDaybookResponse | null>(
null
);

const [daybookData, setDaybookData] = useState<GetDaybookResponse | null>(null);
const [isLoading, setIsLoading] = useState(false);

const getData = async (id: string) => {
const res = await getDaybook(id);
if (!res || !res.data) return;
const getData = async (id: string) => {
setIsLoading(true);

setDaybookData(res.data);
try {
const res = await getDaybook(id);
if (!res || !res.data) return;
setDaybookData(res.data);
} finally {
setIsLoading(false);
}
};

useEffect(() => {
if (!id) return;
useEffect(() => {
if (!id) return;

getData(id);
}, [id]);
getData(id);
}, [id]);

if (!daybookData) return <LoadingSpinner />;

return (
<>
<Header>
<Header.Button variety="back" />
다른 사람 일지
</Header>

<Wrapper>
{daybookData && <Card isDetail daybook={daybookData} />}
</Wrapper>

<OthersWritingFooter />
</>
);
return (
<>
{isLoading && <LoadingSpinner />}
<Header>
<Header.Button variety="back" />
다른 사람 일지
</Header>
<Wrapper>
{daybookData && <Card isDetail daybook={daybookData} />}
</Wrapper>
<OthersWritingFooter />
</>
);
};

export default OthersWriting;

const Wrapper = styled.div`
width: 100%;
padding-left: 16px;
padding-right: 16px;
display: flex;
justify-content: center;
align-items: center;
${fadeLeftDelayAnimation};
`
width: 100%;
padding-left: 16px;
padding-right: 16px;
display: flex;
justify-content: center;
align-items: center;
${fadeLeftDelayAnimation};
`;
6 changes: 2 additions & 4 deletions src/components/OthersDayBookFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ const OthersWritingFooter = () => {
return (
<Footer>
<div>
<Link to={'/write'}>
나도 일지 작성하기
</Link>
<Link to={"/write"}>나도 일지 작성하기</Link>
</div>
</Footer>
);
Expand Down Expand Up @@ -43,7 +41,7 @@ const Footer = styled.footer`
display: flex;
justify-content: center;
align-items: center;
max-width: 362px;
}
`;

0 comments on commit ce71f52

Please sign in to comment.