Skip to content

Commit

Permalink
refactor : create a custom debounce method and other refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajeyakrishna-k committed Jul 24, 2023
1 parent 552c47f commit 77dba12
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
12 changes: 6 additions & 6 deletions app/components/progress-bar.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div ...attributes class='progress-bar-container'>
<div ...attributes class='progress-bar'>
<input
{{focus-when this.isEditable}}
aria-label='progress slider for IN-Progress tasks'
Expand All @@ -18,26 +18,26 @@
data-test-progress-bar-button
{{on 'click' this.turnEditModeOn}}
class='progress-bar__button
{{unless this.isEditable "progress-bar__edit-hover"}}'
{{unless this.isEditable "progress-bar__button--hover"}}'
type='button'
>
{{#if this.isEditable}}
{{@value}}
<span class='progress-bar__button__text'>{{@value}}</span>
{{else}}
<svg
class='progress-bar__edit-icon'
class='progress-bar__button__edit-icon'
viewBox='0 0 24 24'
fill='none'
xmlns='http://www.w3.org/2000/svg'
>
<path
class='progress-bar__edit-icon-path-inner'
class='progress-bar__button__edit-icon__inner'
opacity='0.5'
d='M4 20H8L18 10L14 6L4 16V20Z'
fill='#000000'
/>
<path
class='progress-bar__edit-icon-path-outer'
class='progress-bar__button__edit-icon__outer'
d='M18 10L21 7L17 3L14 6M18 10L8 20H4V16L14 6M18 10L14 6'
stroke='#000000'
stroke-width='1.5'
Expand Down
5 changes: 3 additions & 2 deletions app/components/progress-bar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { debounce } from 'lodash';
import { debounce } from '../utils/debounce';
export default class ProgressBarComponent extends Component {
@tracked isEditable = false;
@tracked value = this.args.value;
Expand All @@ -15,7 +15,8 @@ export default class ProgressBarComponent extends Component {

setEditableToFalse() {
setTimeout(() => {
if (this.isEditable && Date.now() - this.lastEditTime >= 5000) {
const timeDelta = Date.now() - this.lastEditedTime;
if (this.isEditable && timeDelta >= 5000) {
this.isEditable = false;
} else if (this.isEditable) {
this.setEditableToFalse();
Expand Down
32 changes: 20 additions & 12 deletions app/styles/progress-bar.css
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
:root {
--progress-bar-color: rgba(0, 128, 0, 0.9);
--light-grey:rgba(128, 128, 128, 0.5);
--light-grey: rgba(128, 128, 128, 0.5);
--black: black;
--white: white;
}
.progress-bar-container {
.progress-bar {
display: flex;
flex-direction: row;
gap: 4px;
}

.progress-bar__button {
width: 1.4rem;
width: 1.5rem;
height: 1.1rem;
font-size: 60%;
font-weight: bolder;
text-justify: auto;
border: 2px solid var(--black);
border-radius: 4px;
background-color: transparent;
display: flex;
align-items: center;
justify-items: center;
}

.progress-bar__button__text {
font-size: 0.6em;
font-weight: bolder;
margin: auto;
}

.progress-bar__edit-icon {
width: 95%;
height: 95%;
margin-bottom: 2px;
.progress-bar__button__edit-icon {
width: 1rem;
height: 1rem;
margin: 3px;
}
.progress-bar__input-slider {
-webkit-appearance: none;
Expand All @@ -36,6 +43,7 @@
border: 2px solid var(--black);
border-radius: 4px;
}

.progress-bar__input-slider:focus {
box-shadow: 0 0 0 1px var(--progress-bar-color);
}
Expand Down Expand Up @@ -65,10 +73,10 @@
);
}

.progress-bar__edit-hover:hover {
.progress-bar__button--hover:hover {
background-color: var(--light-grey);
}

.progress-bar__edit-icon-path-inner {
.progress-bar__button__edit-icon__inner {
fill: var(--progress-bar-color);
}
10 changes: 10 additions & 0 deletions app/utils/debounce.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const debounce = (func, delay) => {
let timerId;

return (...args) => {
clearTimeout(timerId);
timerId = setTimeout(() => {
func.apply(this, args);
}, delay);
};
};
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"ember-cli-qrcode": "^2.1.0",
"ember-click-outside": "^5.0.1",
"ember-resources": "^5.6.0",
"lodash": "^4.17.21",
"mixpanel-browser": "^2.43.0",
"webpack": "^5.74.0",
"webpack-5": "^0.0.0"
Expand Down

0 comments on commit 77dba12

Please sign in to comment.