-
Notifications
You must be signed in to change notification settings - Fork 0
/
App1.js
167 lines (137 loc) · 3.57 KB
/
App1.js
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
/* esLint-disable*/
import './SomeForm.js';
import './App.css';
import React, {useState} from 'react';
import {Helmet} from 'react-helmet';
function App1() {
let [따봉, 따봉변경] = useState(0);
let [ 글제목,글제목변경] = useState(['남자 코트 추천', '하루만에 끝내자','블로그 마지막 리스트']);
let [날짜, 날짜변경] = useState(['2021-08-03', '2021-08-01', '2021-08-02']);
function ListItem(props){
const value = props.value;
return(
<li key = {value.toString()}>
{value}
</li>
);
}
function NumberList(props){
const numbers = props.numbers;
const listItems = numbers.map((number)=>
<ListItem value ={number}/>
);
return(
<ul>
{listItems}
</ul>
);
}
function 제목바꾸기(){
var newArray = [...글제목];
console.log(newArray);
글제목변경(newArray);
}
function 최신순(){
let mapped = 날짜.map(function(el, i){
return {index: 글제목[i], value : el};
})
mapped.sort(function(a,b){
return +(a.value>b.value)||+(a.value===b.value)-1;
});
let time =[]
let title = []
for(let i =0;i<mapped.length;i++){
title.push(mapped[i]['index']);
time.push(mapped[i]['value']);
}
글제목변경(title);
날짜변경(time);
}
function 오래된순(){
let mapped = 날짜.map(function(el, i){
return {index: 글제목[i], value : el};
})
mapped.sort(function(a,b){
return -(a.value>b.value)||-(a.value===b.value)-1;
});
let time =[]
let title = []
for(let i =0;i<mapped.length;i++){
title.push(mapped[i]['index']);
time.push(mapped[i]['value']);
}
글제목변경(title);
날짜변경(time);
}
return (
<div className="App">
<div className="black-nav">
<div>개발 Blog</div>
</div>
<div style = {{padding : "20px"}}>
<button style = {{ color : 'black' , backgroundColor : 'white', display : "flex", padding : "10px" }} onClick={최신순}><strong>최신 순</strong></button>
</div>
<div style = {{padding : "20px"}}>
<button style = {{color : 'black', backgroundColor:'white', display:'flex', padding:'10px'}} onClick={오래된순}><strong>오래된 순</strong></button>
</div>
<div className = "list">
<PostList
value = {0}
title = {글제목}
date = {날짜}
따봉 = {따봉}
따봉변경= {따봉변경}
/>
<hr/>
<PostList
value = {1}
title = {글제목}
date = {날짜}
따봉={따봉}
따봉변경={따봉변경}
/>
<hr/>
<PostList
value = {2}
title = {글제목}
date = {날짜}
따봉={따봉}
따봉변경={따봉변경}
/>
<hr></hr>
</div>
<Modal></Modal>
</div>
);
}
function PostList({value, title,date, 따봉, 따봉변경}){
if(value ===0){
return (
<div>
<h3>{title[value]}<button onClick = {()=>{따봉변경(따봉+1)}}>👍</button>{따봉}</h3>
<p>{date[value]}</p>
</div>
)
}
else{
return(
<div>
<h3>{title[value]}</h3>
<p> {date[value]}</p>
</div>
)
}
}
function Modal(){// component 명 대문자 시작
return (
<>
<div className = "modal">
<h2>제목</h2>
<p>날짜</p>
<p>상세내용</p>
</div>
<div></div>
</>
)
}
export default App1;