Skip to content

Commit

Permalink
pass time as a prop to component
Browse files Browse the repository at this point in the history
  • Loading branch information
sumitd94 committed Nov 24, 2023
1 parent 2973166 commit d9573be
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/components/self-clear-cache.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{#if @dev}}
<section class='cache'>
<div data-test-last-time class='cache__last-request'>
Last Request: 24 November, 1:23 PM IST
Last Request: {{@time}}
</div>
<button
data-test-btn-clear-cache
Expand Down
2 changes: 2 additions & 0 deletions app/constants/self-clear-cache.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export const MAX_CACHE_PURGE_COUNT = 3;
// this will be removed once we fetch this from the API
export const LAST_UPDATED_REQUEST = '24 November, 1:23 PM IST';
15 changes: 11 additions & 4 deletions app/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import ENV from 'website-my/config/environment';
import { inject as service } from '@ember/service';
import { toastNotificationTimeoutOptions } from '../constants/toast-notification';
import { USER_STATES } from '../constants/user-status';
import { MAX_CACHE_PURGE_COUNT } from '../constants/self-clear-cache';
import {
MAX_CACHE_PURGE_COUNT,
LAST_UPDATED_REQUEST,
} from '../constants/self-clear-cache';

const BASE_URL = ENV.BASE_API_URL;

export default class IndexController extends Controller {
queryParams = ['dev'];
@service featureFlag;
@service toast;
@tracked status = this.model;
Expand All @@ -19,6 +21,7 @@ export default class IndexController extends Controller {
@tracked newStatus;
@tracked isPurgingCache = false;
@tracked cacheTriggeredPending = MAX_CACHE_PURGE_COUNT;
@tracked lastUpdatedCacheRequest = LAST_UPDATED_REQUEST;

@action toggleUserStateModal() {
this.showUserStateModal = !this.showUserStateModal;
Expand Down Expand Up @@ -91,7 +94,7 @@ export default class IndexController extends Controller {
if (response.ok) {
const data = await response.json();
this.cacheTriggeredPending--;
alert(data.message);
this.toast.success(data.message, '', toastNotificationTimeoutOptions);
} else {
this.toast.error(
'Something went wrong.',
Expand All @@ -101,7 +104,11 @@ export default class IndexController extends Controller {
}
} catch (error) {
console.error('Error : ', error);
alert('Something went wrong!');
this.toast.error(
'Something went wrong.',
'',
toastNotificationTimeoutOptions
);
} finally {
this.isPurgingCache = false;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/components/self-clear-cache-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module('Integration | Component | self-clear-cache', function (hooks) {
cacheTriggeredPending: 3,
isDevMode: true,
isPurgingCache: false,
lastUpdatedCacheRequest: '24 November, 1:23 PM IST',
});

await render(hbs`
Expand All @@ -20,6 +21,7 @@ module('Integration | Component | self-clear-cache', function (hooks) {
@onClearCache={{this.purgeCache}}
@isPurgingCache={{this.isPurgingCache}}
@dev={{this.isDevMode}}
@time={{this.lastUpdatedCacheRequest}}
/>
`);

Expand Down

0 comments on commit d9573be

Please sign in to comment.