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

adds component for updating user status #82

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/components/user-status.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div class="heading">
{{#if (eq @status "active")}}
<h2 data-test-status>I am doing a task</h2>
{{/if}}
{{#if (eq @status "idle")}}
<h2 data-test-status>I am idle</h2>
{{/if}}
{{#if (eq @status "ooo")}}
<h2 data-test-status>I am OOO</h2>
{{/if}}
Comment on lines +2 to +10
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems repetitive, I would suggest to instead set the string in the js file and simply have a single

    <h2 data-test-status> {{this.currentUserStatus}} </h2>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay

</div>
<div class="buttons">
{{#if (eq @status "active")}}
<button class="buttons__idle" type="button" {{on "click" (fn @onUpdateStatus 'idle')}}><span data-test-button-text>Change status to ‘Idle’</span></button>
<button class="buttons--small" type="button" {{on "click" (fn @onUpdateStatus 'ooo')}}><span>Mark yourself as OOO</span></button>
{{/if}}
{{#if (eq @status "idle")}}
<button class="buttons__active" type="button" data-test-button {{on "click" (fn @onUpdateStatus 'active')}}><span data-test-button-text>Change status to ‘Doing a task’</span></button>
<button class="buttons--small" type="button" {{on "click" (fn @onUpdateStatus 'ooo')}}><span>Mark yourself as OOO</span></button>
Copy link
Contributor

Choose a reason for hiding this comment

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

A modifier class is added along side a base class.
Something like <button class="buttons buttons--small" ....

You can check out http://getbem.com/naming/ or reach out to me if you have any queries :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah right! Thank you :)

{{/if}}
{{#if (eq @status "ooo")}}
<button class="buttons--small" type="button" {{on "click" (fn @onUpdateStatus 'active')}}><span>Mark yourself as Active again</span></button>
{{/if}}
</div>
Comment on lines +12 to +24
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here, the view seems to be doing a bunch of logic handling

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 Okay :)

29 changes: 29 additions & 0 deletions app/controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Controller from '@ember/controller';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import ENV from 'website-my/config/environment';

const BASE_URL = ENV.BASE_API_URL;

export default class IndexController extends Controller {
@tracked status = this.model;

@action async updateStatus(status) {
this.status = status;
try {
const response = await fetch(`${BASE_URL}/users/self`, {
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious why the fetching of data is happening in the controller and not the route. Also are we not using Ember Data?

method: 'PATCH',
body: JSON.stringify({
status,
}),
headers: {
'Content-Type': 'application/json',
},
credentials: 'include',
});
console.log(response);
Copy link
Contributor

Choose a reason for hiding this comment

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

No stray console logs in prod please :)

} catch (error) {
console.error('Error : ', error);
}
}
}
15 changes: 15 additions & 0 deletions app/routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Route from '@ember/routing/route';
import ENV from 'website-my/config/environment';

const API_BASE_URL = ENV.BASE_API_URL;

export default class TasksRoute extends Route {
model = async () => {
const response = await fetch(`${API_BASE_URL}/users/self`, {
credentials: 'include',
});
const userData = await response.json();

return userData.status;
};
}
1 change: 1 addition & 0 deletions app/styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@import "image-upload.css";
@import "tasks.css";
@import "sidebar.css";
@import "index-buttons.css";

body {
font-family: "Roboto", sans-serif, serif;
Expand Down
44 changes: 44 additions & 0 deletions app/styles/index-buttons.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.heading h2{
color: #0034a5;
margin-bottom: 40px;
margin-top: 50px;
font-size: 1.5rem;
}

.buttons {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

.buttons__idle {
font-size: 1rem;
color: #e49504;
font-weight: 600;
border: 1px solid #e49504;
padding: 20px;
width: 18%;
margin-bottom: 40px;
border-radius: 10px;
background: #ffff;
}

.buttons__active {
font-size: 1rem;
font-weight: 600;
color: #16a334;
border: 1px solid #16a334;
border-radius: 10px;
padding: 20px;
margin-bottom: 40px;
background: #ffff;
}

.buttons--small {
font-size: 0.6rem;
font-weight: 600;
color: #0034a5;
border: none;
background: #ffff;
}
5 changes: 4 additions & 1 deletion app/templates/index.hbs
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
Index page works!
<UserStatus
@status={{this.status}}
@onUpdateStatus={{this.updateStatus}}
/>