forked from feialm/KOMA-APP-BARS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormSite.js
278 lines (219 loc) · 7.68 KB
/
FormSite.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
import React, { useState } from 'react';
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
import logo from './logo.svg';
import './App.css';
import ReactDOM from "react-dom";
//import Child from "./Child.js"
//vårt nästa sak är att vi vill försöka skicka vårt course till vårt child så att dem får en props
function Parent(){
const [localData, setLocalData] = useState(loadData());
const [redirect, setRedirect] = useState(false);
function saveData(a){
window.localStorage.setItem("data", JSON.stringify(a));
setRedirect(true);
}
//denna eller funktion gör vi i falla att det är null i localstarage
function loadData(){
try {
const storage = JSON.parse(window.localStorage.getItem("data"));
return storage || [];
} catch (e) {
return [];
}
}
function setData(data){
setLocalData(data);
saveData(data);
}
function colour(){
var props = loadData();
let arrayFromStorage = JSON.parse(localStorage.getItem("data"));
var colorCounter = props.length;
console.log(colorCounter)
console.log('colorCounter');
let colour1 = "white";
var mod = colorCounter % 5;
if (mod === 0){
colour1 = "#f92672"; //rosa
}
else if (mod === 1){
colour1 = "#a6e22e"; //grön #33c474
}
else if (mod === 2){
colour1 = "#66d9ef" //blå #4ac3ff
}
else if (mod === 3){
colour1 = "#ae81ff"; //lila #ca45ff
}
else if (mod === 4){
colour1 = "#fd971f"; //orange
}
else
colour1="yellow";
colorCounter= colorCounter+1;
console.log(colorCounter);
return colour1;
}
function fixObject (a, b, c, d, e) {
console.log(a)
if (a === ""){
a = "NoName"
console.log("NoName achived")
}
if(b == ""){
b = "12/11/2019"
}
if(c == ""){
c = "12/24/2020"
}
let TotTime = (Number(d)*60) + Number(e);
let g = String(); //reptime
let f = String(TotTime);
const Course = {id: a, startDate: b, endDate: c, totTime: f, repTime: g, repTodayTime: "0", color: colour()};
addtoList(Course);
}
function addtoList(courseToAdd){
localData.push(courseToAdd);
setData(localData);
}
return(
<div>
<App fixObjectEtikett={fixObject} />
</div>
);
}
//App är form
function App(props) { // props eller inte props??
console.log("vad får vi in??");
console.log(props);
console.log("Fick vi");
/*QuestionButtonandList*/
const [hideQuestion, triggerHideQuestion] = useState(true);
const [questionWidth, changeQuestionWidth] = useState(0);
const [questionOpacity, changeQuestionOpacity] = useState("100%");
const [closeQuestionOpacity, changeCloseQuestionOpacity] = useState("0%");
function handleClickQuestion() {
if(hideQuestion){
triggerHideQuestion(false);
changeQuestionWidth("100%");
changeQuestionOpacity("0%");
changeCloseQuestionOpacity("100%");
}
else{
triggerHideQuestion(true);
changeQuestionWidth("0");
changeQuestionOpacity("100%");
changeCloseQuestionOpacity("0%");
}
console.log('hej du klickade på frågetecknet');
}
function questionText(){
if(hideQuestion === false){
return(
<div className="questionWrapper">
<div className="appHeader">
<h1 className="title">HELP<br/></h1>
</div>
<div className="questionText center">
<p className="helpTitle">To do List</p>
<p className="helpText">-centera meny √ <br/> -skriva text till help <br/> -hitta på namn <br/> -footer swipe</p>
<p className="helpTitle">To do List</p>
<p className="helpText">-centera meny √ <br/> -skriva text till help <br/> -hitta på namn <br/> -footer swipe</p>
<p className="helpTitle">To do List</p>
<p className="helpText">-centera meny √ <br/> -skriva text till help <br/> -hitta på namn <br/> -footer swipe</p>
<p className="helpTitle">To do List</p>
<p className="helpText">-centera meny √ <br/> -skriva text till help <br/> -hitta på namn <br/> -footer swipe</p>
<p className="helpTitle">To do List</p>
<p className="helpText">-centera meny √ <br/> -skriva text till help <br/> -hitta på namn <br/> -footer swipe</p>
</div>
</div>
);
}
}
/*QuestionButtonandList End*/
const [name, setCoursName] = useState('');
const [startDate, setStartDate] = useState(0);
const [endDate, setEndDate] = useState(0);
const [hours, setHours] = useState(2);
const [min, setMin] = useState(0);
function changeInput(event){
if(event.target.id === "name"){
setCoursName(event.target.value);
}
else if(event.target.id == "startDate"){
setStartDate(event.target.value);
}
else if(event.target.id == "endDate"){
setEndDate(event.target.value);
}
else if(event.target.id == "hours"){
setHours(event.target.value);
}
else{
setMin(event.target.value);
}
}
/*Main render for FormSite*/
return (
<div className="center">
<div className="appHeader head">
<Link to="/">
<div className="fitText">
<h1>StudyUp</h1>
</div>
</Link>
<p className="h3">Create your activity!</p>
</div>
<div className="mainBody">
{/*Question Button*/}
<div className="questionButton smalCirkel" onClick={handleClickQuestion}>
<p className="question removeMargin">?</p>
</div>
{/*Question List*/}
<div className="questionID" style={{width: questionWidth}}>
{questionText()}
</div>
<div className="wrapperOutline fitText">
<div className="wrapperAddName">
<p className="addActivityText" id="activityName">Activity Name</p>
<input className="textBox" id="name" type="text" placeholder="Name" onChange={changeInput}/>
</div>
<div className="wrapperDate">
<div className="wrapperStartDate">
<p className="addActivityText">Start Date</p>
<input className="dateBox" id="startDate" type="text" placeholder="mm/dd/yyyy" onChange={changeInput}/>
</div>
<div className="wrapperEndDate">
<p className="addActivityText">End Date</p>
<input className="dateBox" id="endDate" type="text" placeholder="mm/dd/yyyy" onChange={changeInput}/>
</div>
</div>
<div className="wrapperAddTime">
<p className="addActivityTime">Set time:</p>
<div className="time">
<input className="timeBox" type="text" placeholder="h" onChange={changeInput}/>
<p className="timeIndicator">h</p>
<input className="timeBox" type="text" placeholder="m" onChange={changeInput}/>
<p className="timeIndicator">m</p>
</div>
</div>
</div>
<div className="addActivityButton fitText">
<Link to="/BarSite.js"><button onClick={() => props.fixObjectEtikett(name,startDate,endDate,hours,min)} className="greenButton center" id="formSaveButton">
<p className="buttonText pBlack">Save</p>
</button></Link>
<div className="addActivityCancelReset">
<Link to="/BarSite.js"><button className="redButton">
<p className="buttonText pBlack">Cancel</p>
</button></Link>
</div>
</div>
{/*Footer*/}
<div className="App-bottom">
<p className="dots">Bottom Header</p>
</div>
</div>
</div>
);
}
export default Parent;//ska det vara parent eller app här?