Skip to content

Commit

Permalink
[Edit] time stamp
Browse files Browse the repository at this point in the history
  • Loading branch information
winnieworld committed Oct 10, 2023
1 parent 9d647b7 commit 61e6a66
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
26 changes: 25 additions & 1 deletion app/components/Feed/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@ import styled from "styled-components";
interface Props {
feeds?: FeedInfoType[];
}
export const timeForToday = (value: string) => {
const today = new Date();
const timeValue = new Date(value);

const betweenTime = Math.floor(
(today.getTime() - timeValue.getTime()) / 1000 / 60
);
if (betweenTime < 1) return "방금전";
if (betweenTime < 60) {
return `${betweenTime}분전`;
}

const betweenTimeHour = Math.floor(betweenTime / 60);
if (betweenTimeHour < 24) {
return `${betweenTimeHour}시간전`;
}

const betweenTimeDay = Math.floor(betweenTime / 60 / 24);
if (betweenTimeDay < 365) {
return `${betweenTimeDay}일전`;
}

return `${Math.floor(betweenTimeDay / 365)}년전`;
};

const Feed: React.FC<Props> = ({ feeds }) => {
return (
Expand Down Expand Up @@ -95,7 +119,7 @@ const Feed: React.FC<Props> = ({ feeds }) => {
<ContentNickName>{feed.nickName}</ContentNickName>
<Discription>{feed.contents}</Discription>
</FlexBox>
<Time>{feed.updated_at}</Time>
<Time>{timeForToday(feed.updated_at)}</Time>
</Content>
</div>
))}
Expand Down
1 change: 0 additions & 1 deletion app/components/Login/LoginBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const LoginBox = () => {
sessionStorage.setItem("access", data.access_token);
router.push("/home");
} else {
console.log(data);
setError(data.message.includes("ID") ? "email" : "pw");
}
});
Expand Down
13 changes: 9 additions & 4 deletions app/create/FileLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { ChangeEvent, useState } from "react";
import AliceCarousel from "react-alice-carousel";
import "react-alice-carousel/lib/alice-carousel.css";
import { createBoard } from "../../axios/boards/index";
import Link from "next/link";
import { useRouter } from "next/navigation";

import styled from "styled-components";

interface filesType {
Expand All @@ -17,6 +18,8 @@ const FileLoader = () => {
const [title, setTitle] = useState<string>("");
const [contents, setContents] = useState<string>("");
// 이미지 상대경로 저장
const router = useRouter();

const handleAddImages = (event: any) => {
const imageLists = event.target.files;
if (event.target.files.length > 1) {
Expand Down Expand Up @@ -46,9 +49,11 @@ const FileLoader = () => {

const res = createBoard(formData);
res.then((info) => {
if (info.code !== 200) console.log(info.message);
else {
console.log(info);
if (info.status === 201) {
alert("게시글이 등록되었어요!");
router.push("/home");
} else {
alert("게시글이 등록에 실패하였어요 ㅜ");
}
});
};
Expand Down
2 changes: 1 addition & 1 deletion axios/boards/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const createBoard = async (formData: any) => {
"Content-Type": "multipart/form-data",
},
});
return response.data;
return response;
} catch (error: any) {
console.log(error);
// alert('다시 시도해주세요');
Expand Down
1 change: 0 additions & 1 deletion hooks/useAuthRedirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useEffect } from "react";

export const useAuthRedirect = () => {
const navigate = useRouter();
console.log("a");
const access =
typeof window !== "undefined" ? sessionStorage.getItem("access") : null;

Expand Down

0 comments on commit 61e6a66

Please sign in to comment.