diff --git a/app/components/self-clear-cache.hbs b/app/components/self-clear-cache.hbs
new file mode 100644
index 00000000..fca13aac
--- /dev/null
+++ b/app/components/self-clear-cache.hbs
@@ -0,0 +1,21 @@
+{{#if @dev}}
+
+
+ Last Request: {{@time}}
+
+
+
+ {{@totalTimes}}
+ / 3 requests remaining for today
+
+
+{{/if}}
\ No newline at end of file
diff --git a/app/constants/self-clear-cache.js b/app/constants/self-clear-cache.js
new file mode 100644
index 00000000..64068cc0
--- /dev/null
+++ b/app/constants/self-clear-cache.js
@@ -0,0 +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';
diff --git a/app/controllers/index.js b/app/controllers/index.js
index 42ef5e5e..dbd87934 100644
--- a/app/controllers/index.js
+++ b/app/controllers/index.js
@@ -5,20 +5,32 @@ 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,
+ LAST_UPDATED_REQUEST,
+} from '../constants/self-clear-cache';
const BASE_URL = ENV.BASE_API_URL;
export default class IndexController extends Controller {
+ @service featureFlag;
@service toast;
@tracked status = this.model;
@tracked isStatusUpdating = false;
@tracked showUserStateModal = false;
@tracked newStatus;
+ @tracked isPurgingCache = false;
+ @tracked cacheTriggeredPending = MAX_CACHE_PURGE_COUNT;
+ lastUpdatedCacheRequest = LAST_UPDATED_REQUEST;
@action toggleUserStateModal() {
this.showUserStateModal = !this.showUserStateModal;
}
+ get isDevMode() {
+ return this.featureFlag.isDevMode;
+ }
+
@action async updateStatus(newStatus) {
this.isStatusUpdating = true;
if (!('cancelOoo' in newStatus)) {
@@ -68,4 +80,37 @@ export default class IndexController extends Controller {
this.newStatus = status;
this.toggleUserStateModal();
}
+
+ @action async purgeCache() {
+ this.isPurgingCache = true;
+ try {
+ const response = await fetch(`${BASE_URL}/cache`, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ credentials: 'include',
+ });
+ if (response.ok) {
+ const data = await response.json();
+ this.cacheTriggeredPending--;
+ this.toast.success(data.message, '', toastNotificationTimeoutOptions);
+ } else {
+ this.toast.error(
+ 'Something went wrong.',
+ '',
+ toastNotificationTimeoutOptions
+ );
+ }
+ } catch (error) {
+ console.error('Error : ', error);
+ this.toast.error(
+ 'Something went wrong.',
+ '',
+ toastNotificationTimeoutOptions
+ );
+ } finally {
+ this.isPurgingCache = false;
+ }
+ }
}
diff --git a/app/styles/app.css b/app/styles/app.css
index 6c77772c..0772d1f0 100644
--- a/app/styles/app.css
+++ b/app/styles/app.css
@@ -20,6 +20,7 @@
@import 'progress-bar.css';
@import 'mobile.css';
@import 'components/mobile-dialog.css';
+@import 'self-clear-cache.css';
html,
body {
@@ -41,7 +42,7 @@ body {
.main-container {
margin: 0;
padding: 0;
- flex: 100%;
+ flex: 100%;
display: flex;
flex-direction: column;
}
diff --git a/app/styles/self-clear-cache.css b/app/styles/self-clear-cache.css
new file mode 100644
index 00000000..ec190bc3
--- /dev/null
+++ b/app/styles/self-clear-cache.css
@@ -0,0 +1,35 @@
+.cache {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ margin: auto;
+ box-shadow: 5px 10px 15px #09113344;
+ border-radius: 10px;
+ padding: 30px;
+ font-weight: 700;
+}
+
+.cache__last-request {
+ padding: 40px 4px 20px;
+ color: #1d1283;
+ font-size: 2rem;
+ text-align: center;
+}
+
+.cache__clear-btn {
+ border-radius: 10px;
+ padding: 16px 60px;
+ border: 3px solid #e49504;
+ color: #e49504;
+ background-color: white;
+ font-weight: 700;
+ font-size: 1.25rem;
+ cursor: pointer;
+}
+
+.cache__remaining-requests {
+ padding-top: 30px;
+ color: #1d1283;
+ font-size: 1.25rem;
+}
diff --git a/app/templates/index.hbs b/app/templates/index.hbs
index c377e590..7282738e 100644
--- a/app/templates/index.hbs
+++ b/app/templates/index.hbs
@@ -1,8 +1,15 @@
-
+
Welcome to my site!
-
+
{},
+ cacheTriggeredPending: 3,
+ isDevMode: true,
+ isPurgingCache: false,
+ lastUpdatedCacheRequest: '24 November, 1:23 PM IST',
+ });
+
+ await render(hbs`
+
+ `);
+
+ assert
+ .dom('[data-test-pending-requests]')
+ .hasText(`3 / 3 requests remaining for today`);
+ assert.dom('[data-test-btn-clear-cache]').hasText('Clear Cache');
+ assert
+ .dom('[data-test-last-time]')
+ .hasText('Last Request: 24 November, 1:23 PM IST');
+ });
+});