-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated home page, connected it with the API #18
base: master
Are you sure you want to change the base?
Conversation
f2ad81e
to
87e9cf2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi. Unfortunately, there are some new issues in your PR, some of them are more serious than the others. Maybe it's too late (or probably not), but apparently it might be a good idea to split the PR into two smaller ones, for example, one introducing static HTML pages and the other one adding JS. But if you decide to leave it as one PR, I think there should be 4 approvals before we merge it, because there are updates (and therefore there are issues) of very different kinds (thank god there are no changes to the API or database schemes in this PR)
src/webhandlers.go
Outdated
@@ -172,6 +172,17 @@ func main() { | |||
r.HandleFunc("/api/days/brief", HandleApiDaysBrief).Methods("GET") | |||
//r.HandleFunc("/api/days/{id:[0-9]+}") | |||
|
|||
//r.Handle("/src", ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a mistake
src/webhandlers.go
Outdated
r.HandleFunc("/scripts/*", func(w http.ResponseWriter, r *http.Request) { | ||
r.URL.Path = r.URL.Path[len("/scripts"):] | ||
http.FileServer(http.Dir("src/scripts")).ServeHTTP(w, r) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be here either... The following handler does everything you want
src/templates/index.html
Outdated
<title>Welcome to Life Calender!</title> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> | ||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto"> | ||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat"> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> | ||
<style> | ||
.w3-sidebar a {font-family: "Roboto", sans-serif} | ||
body,h1,h2,h3,h4,h5,h6,.w3-wide {font-family: "Montserrat", sans-serif;} | ||
.square { | ||
height: 70px; | ||
width: 70px; | ||
background-color: #0b6; | ||
} | ||
</style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is <head>
?!
src/templates/index.html
Outdated
{{if not .}} | ||
Unfortunately, you are not logged in now :(<br> | ||
<a href="/login">Log in!</a> | ||
{{else}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will look better if you will use if condition ... else ...
instead of if not condition ... else ...
src/templates/index.html
Outdated
<a href="/login">Log in!</a> | ||
{{else}} | ||
<!-- Sidebar/menu --> | ||
<nav class="w3-sidebar w3-bar-block w3-white w3-collapse w3-top" style="z-index:3;width:265px" id="mySidebar"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(not sure) Probably id="mySidebar"
shouldn't get into master
(there are similar issues among this file)
src/templates/index.html
Outdated
<a href="/login">Log in!</a> | ||
{{else}} | ||
<!-- Sidebar/menu --> | ||
<nav class="w3-sidebar w3-bar-block w3-white w3-collapse w3-top" style="z-index:3;width:265px" id="mySidebar"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is z-index
for here? I don't see any other usages of z-index
on this page...
src/scripts/index.js
Outdated
|
||
methods: { | ||
colorToHex(color) { | ||
function compToHex(c) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the function name mean?
src/scripts/index.js
Outdated
|
||
isDayFilled(day) { | ||
for(let filledDay of this.days) { | ||
if(Date.parse(filledDay.date) === Date.parse(day.toISOString())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think Date.parse
should be called each time. You should (probably) store dates as javascript objects, not as strings. And there definitely should be a better way of converting day
from a Date
object to a timestamp, so at least the right value should be calculated without a call to Date.parse
and outside of the loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not resolved
src/scripts/index.js
Outdated
let threeWeeks = []; | ||
for(let i = 2; i >= 0; --i) { | ||
let currentWeek = []; | ||
for(let j = 6; j >= 0; --j) { | ||
currentWeek.push(new Date(closestSunday)); | ||
currentWeek[6 - j].setUTCDate(closestSunday.getUTCDate() - j - i * 7); | ||
} | ||
threeWeeks.push(currentWeek); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like these loops are going backward and you are pushing to these arrays because you know the arrays' sizes in advance
src/scripts/index.js
Outdated
mounted() { | ||
axios.get("/api/days/brief").then((response) => { | ||
this.days = response.data; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess, should be something like this.days = response.data.days;
. Also, don't forget to handle an API error if it occurs (i. e. response.data.ok
is false
). At least give some message about it (I think an alert
should be enough for now)
Hello, @kolayne! It seems that some issues in backend need to be fixed after merging |
@tanya-kta, I don't understand what kind of changes I've mentioned in my review you are talking about. I think I've resolved the merge conflicts, please, check it out |
41213ac
to
4d115bc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use array.map instead of for-loop (check for a comment)
mounted() { | ||
axios.get("/api/days/brief").then((response) => { | ||
if (response.data.ok) { | ||
this.days = response.data.days; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
4b1ed99
to
53323ab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, there still are some issues... But you seem to work well!
src/scripts/index.js
Outdated
|
||
isDayFilled(day) { | ||
for(let filledDay of this.days) { | ||
if(Date.parse(filledDay.date) === Date.parse(day.toISOString())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not resolved
src/scripts/index.js
Outdated
|
||
getFilledDayColor(day) { | ||
for(let filledDay of this.days) { | ||
if(Date.parse(filledDay.date) === Date.parse(day.toISOString())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
src/scripts/index.js
Outdated
for(let filledDay of this.days) { | ||
if(Date.parse(filledDay.date) === Date.parse(day.toISOString())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because you have to similar pieces of code, I would move them to a separate function - something like findDayByDate
let closestSunday = new Date(); | ||
closestSunday = new Date(Date.UTC(closestSunday.getFullYear(), closestSunday.getMonth(), | ||
closestSunday.getDate() + 7 - closestSunday.getDay())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think if it is worth renaming the variable, but I would at least add a comment that this is not the closest Sunday, but the closest Sunday in future. It is not obvious at all unless you delve into the expression used to calculate it
src/scripts/index.js
Outdated
if (response.data.ok) { | ||
this.days = response.data.days; | ||
this.days.map((day) => { | ||
day.data = new Date(day.data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The field datA of day
is a datE? It is either a dangerous typo or a very bad field name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Field data
of day
is a field mentioned in API docs as a field of API responce, when Date
is a javascript object. If it bothers you, this can be fixed and field data
can be renamed to date
, but I think not in this PR. You may open an issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tanya-kta, I don't understand what you're talking about. I can't find the word "data" in the /api/days/brief
's documentation
Note: such key is mentioned in the docs of /api/activities
(and it also exists in /api/emotions
, because these methods have the same interface), but this piece of code doesn't seem to be anyhow related to those methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sorry, I wasn't right. That's a bug
.w3-sidebar a {font-family: "Roboto", sans-serif} | ||
body,h1,h2,h3,h4,h5,h6,.w3-wide {font-family: "Montserrat", sans-serif;} | ||
.square { | ||
width: 10%; | ||
background-color: #0b6; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something is wrong with indentation/spaces
src/templates/index.html
Outdated
</style> | ||
</head> | ||
<body class="w3-content" style="max-width:98%"> | ||
{{if .}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment must be here!
<script src="https://unpkg.com/vue"></script> | ||
<script src="https://unpkg.com/axios/dist/axios.min.js"></script> | ||
<script src="/scripts/index.js"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The fact you don't know which
rel
to use should not affect the decision whether this should be moved to<head>
or not, of course. I'm asking because I am not closely familiar with the rules of placing scripts on web pages, but I have seen such scripts loaded with thelink
tag inside ofhead
, that's why I am proposing this change - Answering your question,
rel="preload"
is usually used for js
function w3_open() { | ||
document.getElementById("UserSidebar").style.display = "block"; | ||
document.getElementById("Overlay").style.display = "block"; | ||
} | ||
|
||
function w3_close() { | ||
document.getElementById("UserSidebar").style.display = "none"; | ||
document.getElementById("Overlay").style.display = "none"; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like these functions' names. As far as I understand w3
relates to the w3css framework we are using here. But these functions themselves have nothing to do with w3
! I guess this was just copy-pasted from an example/tutorial. If so, the functions should be renamed so that their names reflect the actual purpose of these functions (open/close sidebar menu?)
ui.PathPrefix("/scripts/").Handler(http.StripPrefix("/scripts/", http.FileServer(http.Dir("src/scripts")))). | ||
Methods("GET") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DarkSquirrelComes, how do you like the formatting? Is it ok?
Hi! This is an update of the home page to how it was previously designed and its connection with the API