-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.tsx
executable file
·181 lines (163 loc) · 4.15 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import Head from "next/head";
import Image from "next/image";
import styles from "../styles/Home.module.css";
import React, { useLayoutEffect, useEffect, useState } from "react";
import styled from "styled-components";
import Block from "../components/Block";
import Link from "next/link";
import { instance } from "../utils/instance";
import { Props } from "../types/type";
import { useRouter } from "next/router";
function Home() {
const [posts, setPosts] = useState<Props[]>([]);
const router = useRouter();
useLayoutEffect(() => {
const checkLogin = () => {
if (localStorage.getItem("token") === null) {
router.push("/Signup");
//location.href = "/Signup";
}
};
checkLogin();
}, []);
useLayoutEffect(() => {
const jwt = localStorage.getItem("token");
instance
.get("/users/@me", {
headers: {
Authorization: `Bearer ${jwt}`,
},
})
.then((res) => {
localStorage.setItem("user_id", res.data.id);
instance
.get("/posts", {
headers: {
Authorization: `Bearer ${jwt}`,
},
})
.then((res) => setPosts(res.data));
});
}, []);
const LogOut = () => {
localStorage.removeItem("token");
location.href = "/Signup";
};
const GoMyPage = () => {
const user_id = localStorage.getItem("user_id");
location.href = `/User/${user_id}`;
};
return (
<div>
<Head>
<title>OnakaSNS</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<Header>
<HeaderButton>
<PostIco>
<Link href="/Edit">
<SvgDiv>
<svg xmlns="http://www.w3.org/2000/svg" height="48" width="48">
<path d="M9 39h2.2l22.15-22.15-2.2-2.2L9 36.8Zm30.7-24.3-6.4-6.4 2.1-2.1q.85-.85 2.1-.85t2.1.85l2.2 2.2q.85.85.85 2.1t-.85 2.1Zm-2.1 2.1L12.4 42H6v-6.4l25.2-25.2Zm-5.35-1.05-1.1-1.1 2.2 2.2Z" />
</svg>
</SvgDiv>
</Link>
</PostIco>
<LogOutButton onClick={LogOut}>Sign Out</LogOutButton>
<LogOutButton onClick={GoMyPage}>My Page</LogOutButton>
</HeaderButton>
<LogoImg src="/logo.png" height="60px" />
</Header>
<BG>
<Entire>
<CenterSection>
{posts.map((e) => {
return (
<BlockLine key={e.id}>
<Block props={e} />
</BlockLine>
);
})}
</CenterSection>
</Entire>
</BG>
</div>
);
}
export default Home;
const Header = styled.div`
height: 70px;
width: 100%;
/* top:0px;
left:0px */
background-color: #ffc501;
border-bottom: 2px solid #77477e;
display: flex;
align-items: center;
justify-content: space-between;
position: fixed;
`;
const HeaderButton = styled.div`
display: flex;
align-items: center;
`;
const LogoImg = styled.img`
margin-right: 20px;
`;
const BG = styled.div`
background-color: #fe9600;
background-size: cover;
display: flex;
justify-content: center;
min-height: 100vh;
height: 100%;
padding-top: 70px;
`;
const Entire = styled.div`
display: flex;
justify-content: center;
`;
const CenterSection = styled.div`
width: 800px;
min-height: 100vh;
background-color: #ffee4a;
`;
const BlockLine = styled.div`
text-align: center;
display: flex;
justify-content: center;
`;
const PostIco = styled.div`
background-color: #ffee4a;
height: 60px;
width: 120px;
padding: 7px;
border-radius: 25px;
margin: 0 5px;
display: flex;
align-content: center;
justify-content: center;
border: #77477e solid 2px;
`;
const SvgDiv = styled.div`
fill: #77477e;
`;
const LogOutButton = styled.button`
background-color: #ffee4a;
height: 60px;
width: 120px;
padding: 7px;
margin: 0 5px;
border-radius: 25px;
border: #77477e solid 2px;
color: #77477e;
font-size: 16px;
font-weight: bold;
`;
// .color-0 { color: #fe9600; }
// .color-1 { color: #ffc501; }
// .color-2 { color: #ffee4a; }
// .color-3 { color: #77477e; }
// .color-4 { color: #03001c; }