forked from feialm/KOMA-APP-BARS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BarSite.js
366 lines (294 loc) · 9.8 KB
/
BarSite.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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
//import React from "react";
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
import './App.css';
import { useState } from 'react';
import React, { Component } from 'react';
import ReportTime from "./ReportTime.js";
import CourseInfo from './CourseInfo.js';
var menubool = false;
let i = 0;
function incrementID(){
i++;
}
function colour(i){
let colour1 = "white";
var mod = i % 5;
if (mod === 0){
colour1 = "#f92672"; //rosa
}
else if (mod === 1){
colour1 = "#a6e22e"; //grön #33c474
}
if (mod === 2){
colour1 = "#66d9ef" //blå #4ac3ff
}
if (mod === 3){
colour1 = "#ae81ff"; //lila #ca45ff
}
if (mod === 4){
colour1 = "#fd971f"; //orange
}
incrementID();
return colour1;
}
function timeCalc(total, part){
var percentage = (part/total)*100;
percentage = percentage.toFixed(2);
console.log(total);
console.log(part);
return percentage;
}
function gotoCourseInfo(props){
console.log(props);
console.log("hahahej")
return(
<CourseInfo test={props}/>
);
}
function handleClickActivity(props) {
console.log("grattis du klicka på aktivteten")
gotoCourseInfo(props);
}
function handleClickQuestion(e) {
e.preventDefault();
console.log(' du klickade rätt typ igen');
}
//denna eller funktion gör vi i falla att det är null i localstarage
function loadData(){
//const q = loadData();
try {
const storage = JSON.parse(window.localStorage.getItem("data"));
return storage || [];
} catch (e) {
return [];
}
}
function renderActivities(HHH){
//const b = HHH.courses;
const b = HHH;
// console.log(b[0].name);
//console.log(HHH.name);
return (
HHH.map(c=> (<ActivityInfo key={c.name} a={c} />))
);
}
/*Funktion som ger innehåll genom att skicka in array av objekt*/
function ActivityInfo(HHH) {
const a = HHH.a;
console.log("eheheh");
console.log(a);
let barProgress = timeCalc(a.totTime, a.repTime)+"%";
var same = colour(i);
return(
<Link to="/CourseInfo.js">
<div className="wrapperActivity" onClick={() => handleClickActivity(a)}>
{/*Här ska vi försöka skriva ut arrayen med dess namn och tid */}
<p className="activityName">{a.id}</p>
<div className="activityDetails">
<p className="activityPercentage">{timeCalc(a.totTime, a.repTime)}% done</p>
<p className="activityMoreDetails">More details</p>
</div>
<div className="activityBar" style={{backgroundColor: same, opacity: 0.3}}></div>
<div className="activityProgress" style={{width: barProgress, backgroundColor: same, opacity: 0.8}}></div>
</div>
</Link>
)
}
//}//den här är tillaggd var sist förut!!!!!!!!!!!!
/*renderar sidelementen typ*/
function BarSite(HHH) {
// test
const [ToCourseInfo, setToCourseInfo] = useState(0);
i = 0;
var HHH = loadData();
console.log("JOOOJJJ");
console.log(loadData());
console.log("Elin");
console.log("Pankaka");
console.log(HHH);
console.log("majs");
console.log("Pappa");
console.log(HHH.length);
console.log("Mamma");
/*meny lista typ*/
const [menuWidth, changeMenuWidth] = useState(0);
const [buttonWidth, changeButtonWidth] = useState(0);
const [hideMenu, triggerHideMenu] = useState(true);
const [hideFeedBack, triggerHideFeedBack] = useState(true);
/*Questionbutton and list*/
const [hideQuestion, triggerHideQuestion] = useState(true);
const [questionWidth, changeQuestionWidth] = useState(0);
const [questionOpacity, changeQuestionOpacity] = useState("100%");
const [closeQuestionOpacity, changeCloseQuestionOpacity] = useState("0%");
// const [redirect, setRedirect] = useState(false);
/* om man klickar på question button */
function handleClickQuestion() {
if(hideQuestion){
triggerHideQuestion(false);
changeQuestionWidth("100%");
changeQuestionOpacity("0%");
changeCloseQuestionOpacity("100%");
}
else{
triggerHideQuestion(true);
changeQuestionWidth("0");
changeQuestionOpacity("100%");
changeCloseQuestionOpacity("0%");
}
console.log(' 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>
);
}
}
/* om man klickar på meny-knappen */
function HandleClickMenu(){ /*gör likadant för allt annat, typ?*/
if(hideMenu){ /* öppnar menyn */
triggerHideMenu(false);
changeMenuWidth("100%");
changeButtonWidth("200px");
}
else{ /* göm menyn */
triggerHideMenu(true);
changeMenuWidth("0");
changeButtonWidth("0");
}
}
function HandleClickFeedBack(){
console.log(hideFeedBack); /*gör likadant för allt annat, typ?*/
if(hideFeedBack){
feedBack(); /* öppnar menyn */
triggerHideFeedBack(false);
changeMenuWidth("100%");
changeButtonWidth("200px");
console.log("aaa popup where");
//render popup
}
else{ /* göm menyn */
triggerHideFeedBack(true);
changeMenuWidth("0");
changeButtonWidth("0");
console.log("no popup");
}
}
function reportTime(){
if (hideMenu === false){
return(
<p className="buttonText">Report Time</p>
);
}
}
/*
function handleClickReport() {
console.log(' du klickade på Report');
setRedirect(true);
}
*/
function addActivity(){
if (hideMenu === false){
return(
<p className="buttonText">Add Activity</p>
);
}
}
function deleteActivity(){
if (hideMenu === false){
return(
<p className="buttonText">Delete Activity</p>
);
}
}
function clearList(){
window.localStorage.clear();
window.location.reload(true);
}
function feedBack(){
console.log("FeedBACK respons");
console.log(hideFeedBack);
return(
<div className="feedBack" id="resetButton">
{console.log("FeedBACK respons its false")}
<h1>Warning!</h1>
<p>Are you certain that you want to DELETE al your Courses</p>
<button style={{width: 210} } onClick={() => clearList()} className="purpleButton" id="resetButton">
<p className="buttonText pBlack">Reset</p>
</button>
<button style={{width: 210}} className="redButton" onClick={() => window.location.reload(true)}>
<p className="buttonText pBlack">Cancel</p>
</button>
</div>
);
}
//onClick={clearList()}
return (
<div className="center">
{/*Header*/}
<div className="appHeader head">
<h1 className="title">StudyUp</h1>
<p className="h3">My Activities</p>
</div>
{/*Question Button*/}
<div className="questionButton smalCirkel" onClick={handleClickQuestion}>
<p className="question removeMargin">?</p>
</div>
{/*Question List*/}
<div className="questionID" style={{width: questionWidth}}>
{questionText()}
</div>
{
hideFeedBack ? (null) : (feedBack())
}
{/*Main body*/}
<div className="mainBody">
{renderActivities(HHH)} {/*här ska vi rendera ActivityInfo, för att skriva ut kursinfo*/}
</div>
{/*Menu Button*/}
<div className="menuButton" onClick={HandleClickMenu}>
<div className="menuIcon">
<div className="menu"></div>
<div className="menu"></div>
<div className="menu"></div>
</div>
</div>
{/*Menu List*/}
<div className="menuClass" style={{width: menuWidth}}>
<div className="menuID" style={{width: menuWidth}}></div>
<Link to="/ReportTime.js"><button className="orangeButton reportButton" style={{width: buttonWidth}}>{reportTime()}</button></Link>
<Link to="/"><button className="addButton" style={{width: buttonWidth}}>{addActivity()}</button></Link>
<button className="deleteButton" style={{width: buttonWidth}}>{deleteActivity()}</button>
<button style={{width: buttonWidth}} onClick={HandleClickFeedBack} className="orangeButton resetButton">
<p className="buttonText pBlack">Reset</p>
</button>
</div>
<Link to="/DonutSite.js"><div className="nextPage_right"><p>></p>
</div></Link>
<div>
{/*Footer*/}
<div className="App-bottom">
<p className="dots">Bottom Header</p>
</div>
</div>
</div>
);
}
//return null;
export default BarSite;