update UI

This commit is contained in:
MReenen 2022-01-28 23:17:58 +01:00
parent 37d60c99dd
commit 96e88dc23b
7 changed files with 240 additions and 37 deletions

20
src/components/input.js Normal file
View File

@ -0,0 +1,20 @@
import React from 'react';
class Input extends React.Component {
read(e){
this.props.update(this.props.id, e.target.value)
}
render(){
switch (this.props.type) {
case 'submit':
return <input type="submit" value={this.props.lable} onClick={this.props.submit} />
default:
return <input type={this.props.type} placeholder={this.props.lable} onChange={this.read.bind(this)} />
}
}
}
export default Input;

View File

@ -1,13 +0,0 @@
import React from 'react';
function Task(props) {
let s = "width:" + props.progress + "%"
return (
<div class="task-container">
<div class="task-progress" style={{ width: props.progress + "%" }} ></div>
<div class="task-lable">{props.lable}</div>
</div>
)
}
export default Task;

35
src/db/index.js Normal file
View File

@ -0,0 +1,35 @@
var TaskDb = [
{
'lable': "some stuff",
'progress': 0.5
},{
'lable': "some other stuff",
'progress': 0.2
},{
'lable': "fun stuff",
'progress': 0.75
},
]
class Database{
getTasks(){
return TaskDb;
}
addTask(task){
TaskDb.push(task);
}
updateTask(id, task){
TaskDb[id] = task
}
removeTask(id){
for(let i=id+1; i<TaskDb.length; i++){
TaskDb[i-1] = TaskDb[i];
}
TaskDb.pop();
}
}
export default Database

15
src/res/add.svg Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
viewBox="0 0 80 80"
version="1.1"
id="svg5"
xmlns="http://www.w3.org/2000/svg">
<path
style="fill:none;stroke:#40ae46;stroke-width:5;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 40,10 V 70" />
<path
style="fill:none;stroke:#40ae46;stroke-width:5;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 10,40 H 70" />
</svg>

After

Width:  |  Height:  |  Size: 600 B

35
src/res/trash.svg Normal file
View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="60mm"
height="80mm"
viewBox="0 0 60 80"
version="1.1"
id="svg5"
xmlns="http://www.w3.org/2000/svg">
<g
id="layer1">
<path
style="fill:none;stroke:#40ae46;stroke-width:5;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 5.3255306,9.7780354 H 55.325531"
id="path2165"/>
<path
style="fill:none;stroke:#40ae46;stroke-width:5;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 21.991531,19.778035 3.333999,55"
id="path2165-3-6" />
<path
style="fill:none;stroke:#40ae46;stroke-width:5;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 38.658831,19.778035 -3.3333,55"
id="path2165-3-7" />
<path
style="fill:#40ae46;fill-opacity:1;stroke-width:5.065;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke:none;stroke-opacity:1"
id="path2649"
d="m 26.445361,7.3528442 a 4.2567863,4.8403959 0 0 1 2.119329,-4.2038204 4.2567863,4.8403959 0 0 1 4.261341,-0.00889 4.2567863,4.8403959 0 0 1 2.132873,4.1949544"
/>
<path
style="fill:none;stroke:#40ae46;stroke-width:5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 5.3255306,19.778034 15.325529,74.778035 H 45.32553 L 55.325531,19.778034 Z"
id="path5447" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -6,6 +6,32 @@
--dark-3-color: #444; --dark-3-color: #444;
} }
input{
background: none transparent;
border: none;
border-bottom: var(--dark-3-color) 1px solid;
color: white;
text-align: center;
height: 30px;
width: calc(100% - 50px);
margin: 5px 25px;
}
input[type=text] {
cursor: text;
}
input[type=submit] {
cursor: pointer;
}
input[type=submit]:hover{
background-color: var(--primary-color);
border-radius: 7px;
}
html{
background-color: var(--dark-2-color);
}
body{ body{
padding-top: 75px; padding-top: 75px;
color: white; color: white;
@ -33,10 +59,6 @@ header h1 {
vertical-align: middle; vertical-align: middle;
} }
main{
background-color: var(--dark-2-color);
}
.task-container { .task-container {
background-color: var(--dark-1-color); background-color: var(--dark-1-color);
width: 100%; width: 100%;
@ -46,6 +68,16 @@ main{
margin: 0 0 3px 0; margin: 0 0 3px 0;
} }
.task-container.add {
justify-content: center;
flex-direction: column;
min-height: 50px;
height: auto;
}
.task-container.adding {
padding: 0 0 10px 0;
}
.task-progress{ .task-progress{
position: relative; position: relative;
background-color: var(--primary-color); background-color: var(--primary-color);
@ -59,3 +91,13 @@ main{
position: absolute; position: absolute;
width: 100% width: 100%
} }
.task-trash{
position: absolute;
right: 10px;
height: 30px;
}
.task-add{
height: 30px;
}

View File

@ -1,40 +1,109 @@
import React from 'react' import React from 'react'
import Task from './components/task' import Database from './db'
var tasks = [ import Input from './components/input'
{
'lable': "some stuff", import trashSvg from './res/trash.svg';
'progress': 0.5 import addSvg from './res/add.svg'
},{
'lable': "some other stuff", var db = new Database();
'progress': 0.2
},{ function Details(props){
'lable': "fun stuff", if(!props.display) return ""
'progress': 0.75
}, let ret = []
] let keys = Object.keys(props.task)
for(let i in Object.keys(props.task)){
let key = keys[i]
console.log(key, props.task[key])
ret.push(<span class="task-key">{key}</span>)
ret.push(<span class="task-value">{props.task[key]}</span>)
}
return <div class="task-proppertys">{ret}</div>
}
class Tasks extends React.Component { class Tasks extends React.Component {
constructor(props){ constructor(props){
super(props); super(props);
this.state = tasks; this.state = {
tasks: db.getTasks(),
add: false,
details: -1, // -1 meens don't show details of eny task
};
this.form = {};
} }
updateFromDB() { updateFromDB() {
this.setState(tasks); this.state.tasks = db.getTasks();
this.setState(this.state);
} }
renderOne(task){ trash(id, e){
return <Task lable={task.lable} progress={task.progress * 100} /> db.removeTask(id);
this.updateFromDB();
}
add(e){
this.state.add = true;
this.state.details = -1;
this.setState(this.state);
}
focus(id, e){
this.state.add = false;
this.state.details = id;
this.setState(this.state);
}
renderTask(task, id){
let classes = "task-container"
if(this.state.details == id) classes += " focus"
let progress = (task.progress*100) + "%"
return (
<div class={classes} onClick={this.focus.bind(this, id)}>
<div class="task-progress" style={{ width: progress }} ></div>
<div class="task-lable">{task.lable}</div>
<img class="task-trash" src={trashSvg} alt="del" onClick={this.trash.bind(this, id)} />
<Details display={this.state.details == id} task={task} />
</div>
)
}
valueUpdate(key, value){
this.form[key] = value
}
addSubmit(){
db.addTask({
lable: this.form['lable'],
progress: 0
})
this.updateFromDB()
}
renderAdd(){
if(this.state.add === false)
return (
<div class="task-container add" onClick={this.add.bind(this)}>
<img class="task-add" src={addSvg} alt="+" />
</div>
)
return (
<div class="task-container add adding">
<Input type="text" lable="task" id="lable" update={this.valueUpdate.bind(this)} />
<Input type="submit" lable="save" submit={this.addSubmit.bind(this)} />
</div>
)
} }
render() { render() {
let tasks = [] let tasks = []
for(let i=0; i<this.state.length; i++){ for(let i=0; i<this.state.tasks.length; i++){
tasks.push(this.renderOne(this.state[i])) tasks.push(this.renderTask(this.state.tasks[i], i))
} }
tasks.push(this.renderAdd())
return tasks return tasks
} }
} }