Skip to content
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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

tanya-kta
Copy link
Contributor

Hi! This is an update of the home page to how it was previously designed and its connection with the API

@tanya-kta tanya-kta marked this pull request as ready for review December 6, 2020 16:20
Copy link
Member

@kolayne kolayne left a 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)

@@ -172,6 +172,17 @@ func main() {
r.HandleFunc("/api/days/brief", HandleApiDaysBrief).Methods("GET")
//r.HandleFunc("/api/days/{id:[0-9]+}")

//r.Handle("/src", )
Copy link
Member

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

Comment on lines 176 to 180
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)
})

Copy link
Member

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

Comment on lines 3 to 18
<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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is <head>?!

Comment on lines 21 to 24
{{if not .}}
Unfortunately, you are not logged in now :(<br>
<a href="/login">Log in!</a>
{{else}}
Copy link
Member

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 ...

<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">
Copy link
Member

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)

<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">
Copy link
Member

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...


methods: {
colorToHex(color) {
function compToHex(c) {
Copy link
Member

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?


isDayFilled(day) {
for(let filledDay of this.days) {
if(Date.parse(filledDay.date) === Date.parse(day.toISOString())) {
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not resolved

Comment on lines 39 to 47
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);
}
Copy link
Member

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

Comment on lines 52 to 55
mounted() {
axios.get("/api/days/brief").then((response) => {
this.days = response.data;
});
Copy link
Member

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)

@kolayne kolayne added API / back-end Relates to the API or the back-end Front-end Relates to the front-end labels Dec 7, 2020
@tanya-kta
Copy link
Contributor Author

Hello, @kolayne! It seems that some issues in backend need to be fixed after merging master. They are those two you have mentioned first in your review, I suppose. Please, solve this conflict

@kolayne
Copy link
Member

kolayne commented Dec 14, 2020

@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

Copy link
Member

@DarkSquirrelComes DarkSquirrelComes left a 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@DarkSquirrelComes DarkSquirrelComes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Member

@kolayne kolayne left a 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!


isDayFilled(day) {
for(let filledDay of this.days) {
if(Date.parse(filledDay.date) === Date.parse(day.toISOString())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not resolved


getFilledDayColor(day) {
for(let filledDay of this.days) {
if(Date.parse(filledDay.date) === Date.parse(day.toISOString())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Comment on lines 27 to 28
for(let filledDay of this.days) {
if(Date.parse(filledDay.date) === Date.parse(day.toISOString())) {
Copy link
Member

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

Comment on lines +36 to +38
let closestSunday = new Date();
closestSunday = new Date(Date.UTC(closestSunday.getFullYear(), closestSunday.getMonth(),
closestSunday.getDate() + 7 - closestSunday.getDay()));
Copy link
Member

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

if (response.data.ok) {
this.days = response.data.days;
this.days.map((day) => {
day.data = new Date(day.data);
Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Contributor Author

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

Comment on lines +12 to +17
.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;
}
Copy link
Member

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

</style>
</head>
<body class="w3-content" style="max-width:98%">
{{if .}}
Copy link
Member

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!

Comment on lines +75 to +77
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="/scripts/index.js"></script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tanya-kta,

  1. 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 the link tag inside of head, that's why I am proposing this change
  2. Answering your question, rel="preload" is usually used for js

Comment on lines +79 to +87
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";
}
Copy link
Member

@kolayne kolayne Jan 26, 2021

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?)

Comment on lines +170 to +171
ui.PathPrefix("/scripts/").Handler(http.StripPrefix("/scripts/", http.FileServer(http.Dir("src/scripts")))).
Methods("GET")
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API / back-end Relates to the API or the back-end Front-end Relates to the front-end
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants