Skip to content

Commit c64f10f

Browse files
committed
Make improvements based on work from JS version.
1 parent e9348b2 commit c64f10f

File tree

7 files changed

+37
-58
lines changed

7 files changed

+37
-58
lines changed

dist/index.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
66

7-
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
7+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
88
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
99
<link rel="stylesheet" type="text/css" href="styles.css">
1010
</head>
1111
<body>
1212
<div id="root"></div>
13-
14-
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
15-
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
16-
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
1713
<script src="bundle.js"></script>
1814
</body>
1915
</html>

dist/styles.css

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
11
.padding {
2-
padding: 25px;
2+
padding: 1.55rem;
33
}
44

55
.margin {
6-
margin-left: 5px;
7-
margin-right: 25px;
6+
margin-left: .4rem;
7+
margin-right: 1.55rem;
88
}
99

10-
.flex-column {
11-
display: flex;
12-
flex-direction: column;
13-
}
14-
15-
.flex-center {
16-
display: flex;
17-
justify-content: center;
18-
align-items: center;
19-
}
20-
21-
.flex-container {
22-
display: flex;
23-
justify-content: space-around;
10+
.width-80 {
2411
width: 80%;
2512
}
2613

27-
.list-item {
28-
display: flex;
29-
flex-grow: 1;
30-
font-size: 1.3em;
14+
.font-lg {
15+
font-size: 1.3rem;
3116
}
3217

3318
.red-text {
@@ -39,5 +24,5 @@
3924
}
4025

4126
.fixed-height {
42-
height: 40px
27+
height: 2.5rem;
4328
}

src/components/App.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def render_todo_panel():
4848
xs="12"
4949
>
5050
<Jumbotron>
51-
<div className="flex-column">
52-
<div className="flex-center padding">
51+
<div className="d-flex flex-column">
52+
<div className="d-flex justify-content-center align-items-center padding">
5353
<h2>My Todos</h2>
5454
</div>
5555
{visible_component}

src/components/ButtonPanel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def on_click_logout():
2121
props.logout_user()
2222

2323
return __pragma__("xtrans", None, "{}", """ (
24-
<div className="flex-center">
25-
<div className="flex-container">
24+
<div className="d-flex justify-content-center align-items-center">
25+
<div className="d-flex justify-content-around width-80">
2626
<Button
2727
className="fixed-height"
2828
onClick={on_click_add}

src/components/TodoList.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,28 @@ def on_click_delete(self, todo):
2525
token = self.props.login_user["token"]
2626

2727
def closure():
28-
should_delete = True
29-
if not todo["complete"] and not window.confirm("Delete incomplete Todo?"):
30-
should_delete = False
31-
if should_delete:
28+
if todo.complete or window.confirm('Delete incomplete Todo?'):
3229
self.props.delete_todo(todo["id"], token)
3330
return closure
3431

3532
def render_spinner(self):
33+
if not self.props.todo_list["loading"]:
34+
return None
3635
loading = True
3736
return __pragma__("xtrans", None, "{}", """ (
38-
<div className="flex-center">
37+
<div className="d-flex justify-content-center align-items-center">
3938
<RingLoader
4039
color="#999"
40+
size={42}
4141
loading={loading} />
42+
Loading..
4243
</div>
4344
); """)
4445

4546
def render_checkmark(self, todo):
4647
if todo["complete"]:
4748
return __pragma__("xtrans", None, "{}", """ (
48-
<div className="flex-column flex-center margin">
49+
<div className="d-flex flex-column justify-content-center align-items-center margin">
4950
<FontAwesomeIcon
5051
name="check-circle"
5152
size="2x"
@@ -57,11 +58,11 @@ def render_checkmark(self, todo):
5758
def render_list_item(self, todo):
5859
return __pragma__("xtrans", None, "{}", """ (
5960
<ListGroupItem
60-
className="flex-center"
61+
className="d-flex justify-content-center align-items-center"
6162
key={todo.id}
6263
>
6364
{self.render_checkmark(todo)}
64-
<div className="list-item">
65+
<div className="d-flex flex-grow-1 font-lg">
6566
{todo.text}
6667
</div>
6768
<Button
@@ -80,15 +81,13 @@ def render_list_item(self, todo):
8081

8182
def render(self):
8283
todo_list = self.props["todo_list"]
83-
if todo_list["loading"]:
84-
return self.render_spinner()
85-
8684
list_items = map(self.render_list_item, todo_list["todos"])
8785
return __pragma__("xtrans", None, "{}", """ (
8886
<div>
8987
<ListGroup>
9088
{list_items}
9189
</ListGroup>
9290
<span className="red-text">{todo_list.error}</span>
91+
{self.render_spinner()}
9392
</div>
9493
); """)

src/reducers/login_user.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ def login_user_reducer(state=initial_state, action=None):
2727
"token": action.payload.data["token"]
2828
})
2929
elif type_ in (REGISTER_USER_REJECTED, LOGIN_USER_REJECTED):
30-
msg = action.payload.response.data["message"]
31-
if not msg:
32-
msg = "Unknown Error."
30+
response = action.payload["response"] or None
31+
data = response["data"] if response and response["data"] else None
32+
msg = data["message"] if data and data["message"] else "Unknown Error."
3333
return Object.assign({}, state, {
3434
"loading": False,
3535
"error": msg

src/reducers/todo_list.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from Component_py.stubs import Object # __:skip
22
from actions.types import (
33
FETCH_ALL_TODOS_PENDING, FETCH_ALL_TODOS_FULFILLED, FETCH_ALL_TODOS_REJECTED,
4-
ADD_NEW_TODO_PENDING, ADD_NEW_TODO_FULFILLED, ADD_NEW_TODO_REJECTED,
5-
COMPLETE_TODO_PENDING, COMPLETE_TODO_FULFILLED, COMPLETE_TODO_REJECTED,
6-
DELETE_TODO_PENDING, DELETE_TODO_FULFILLED, DELETE_TODO_REJECTED
4+
ADD_NEW_TODO_FULFILLED, ADD_NEW_TODO_REJECTED,
5+
COMPLETE_TODO_FULFILLED, COMPLETE_TODO_REJECTED,
6+
DELETE_TODO_FULFILLED, DELETE_TODO_REJECTED
77
)
88

99

@@ -17,17 +17,17 @@
1717
def todo_list_reducer(state=initial_state, action=None):
1818
type_ = action["type"]
1919

20-
if type_ in (FETCH_ALL_TODOS_PENDING, ADD_NEW_TODO_PENDING,
21-
COMPLETE_TODO_PENDING, DELETE_TODO_PENDING):
20+
if type_ == FETCH_ALL_TODOS_PENDING:
2221
return Object.assign({}, state, {
23-
"loading": True
22+
"loading": True,
23+
"todos": []
2424
})
2525

2626
elif type_ in (ADD_NEW_TODO_REJECTED, COMPLETE_TODO_REJECTED,
2727
DELETE_TODO_REJECTED):
28-
msg = action.payload.response.data["message"]
29-
if not msg:
30-
msg = "Unknown Error."
28+
response = action.payload["response"] or None
29+
data = response["data"] if response and response["data"] else None
30+
msg = data["message"] if data and data["message"] else "Unknown Error."
3131
return Object.assign({}, state, {
3232
"loading": False,
3333
"error": msg
@@ -38,10 +38,9 @@ def todo_list_reducer(state=initial_state, action=None):
3838
"loading": False,
3939
"todos": []
4040
}
41-
msg = action.payload.response.data["message"]
42-
43-
if not msg:
44-
msg = "Unknown Error."
41+
response = action.payload["response"] or None
42+
data = response["data"] if response and response["data"] else None
43+
msg = data["message"] if data and data["message"] else "Unknown Error."
4544

4645
if "No todos found." not in msg:
4746
mutation["error"] = msg

0 commit comments

Comments
 (0)