From 06ea2a6aa71373582343d82c996c2aec5a1d3c2b Mon Sep 17 00:00:00 2001
From: alaa smadi
Date: Tue, 11 Mar 2025 04:13:32 +0300
Subject: [PATCH 1/9] fix(suggestions list): refactor suggestions sorting
backlog and in progress suggestions should be printed first then print the completed suggestions
---
widget/js/pages/home/index.js | 17 ++++-------------
widget/js/state.js | 2 +-
widget/js/widget.controller.js | 31 +++++++++++++++++++++++++++----
3 files changed, 32 insertions(+), 18 deletions(-)
diff --git a/widget/js/pages/home/index.js b/widget/js/pages/home/index.js
index 6547e40..7965e3d 100644
--- a/widget/js/pages/home/index.js
+++ b/widget/js/pages/home/index.js
@@ -68,7 +68,7 @@ const homePage = {
suggestionTitle.innerHTML = suggestion.title;
suggestionBodyText.innerHTML = suggestion.suggestion;
widgetPagesShared.validateSuggestionImage(suggestionBodyText);
- suggestionVotesCount.innerHTML = `${Object.keys(suggestion.upVotedBy).length}`;
+ suggestionVotesCount.innerHTML = `${Object.keys(suggestion.upVotedBy).length}`;
if (!state.settings.enableComments) {
suggestionCommentContainer.classList.add('hidden');
@@ -223,20 +223,11 @@ const homePage = {
});
if (suggestions.length < state.pageSize) {
- if (state.currentStatusSearch === SUGGESTION_STATUS.COMPLETED) {
+ if (state.isAllNotCompletedSuggestionFetched) {
state.isAllSuggestionFetched = true;
if (!state.suggestionsList.length) this.printEmptyState();
- } else if (state.currentStatusSearch === SUGGESTION_STATUS.INPROGRESS) {
- state.currentStatusSearch = SUGGESTION_STATUS.COMPLETED;
- state.page = 0;
-
- widgetController.getSuggestions().then((suggestions) => {
- this.handleSuggestionPage(suggestions)
- }).catch((err) => {
- console.error(err);
- });
} else {
- state.currentStatusSearch = SUGGESTION_STATUS.INPROGRESS;
+ state.isAllNotCompletedSuggestionFetched = true;
state.page = 0;
widgetController.getSuggestions().then((suggestions) => {
@@ -251,7 +242,7 @@ const homePage = {
init() {
this.initSelectors();
- widgetController.getSuggestions().then((suggestions) => {
+ widgetController.getFirstSuggestionsPage().then((suggestions) => {
setTimeout(() => {
this.destroySkeleton();
diff --git a/widget/js/state.js b/widget/js/state.js
index d5de98c..4a16d0c 100644
--- a/widget/js/state.js
+++ b/widget/js/state.js
@@ -51,9 +51,9 @@ const state = {
settings: new Setting(),
page: 0,
pageSize: 50,
- currentStatusSearch: SUGGESTION_STATUS.BACKLOG,
fetching: false,
isAllSuggestionFetched: false,
+ isAllNotCompletedSuggestionFetched: false,
validUserImages: {},
suggestionsList: [],
updatedUsersData: [],
diff --git a/widget/js/widget.controller.js b/widget/js/widget.controller.js
index 4fb2dcb..4c24806 100644
--- a/widget/js/widget.controller.js
+++ b/widget/js/widget.controller.js
@@ -53,15 +53,17 @@ const widgetController = {
getSuggestions() {
return new Promise((resolve) => {
- const { page, pageSize, settings, currentStatusSearch } = state;
+ const { page, pageSize, settings, isAllNotCompletedSuggestionFetched } = state;
const searchOptions = { page, pageSize };
let $match = {
"_buildfire.index.string1": { $exists: false }
}, $sort = {};
- if (currentStatusSearch === SUGGESTION_STATUS.COMPLETED) {
+ if (isAllNotCompletedSuggestionFetched) {
+ // hide completed immediately
if (settings.hideCompletedItems === 0) return resolve([]);
+ // hide completed after a certain period
if (settings.hideCompletedItems > 0) {
const startDate = new Date();
startDate.setDate(startDate.getDate() - settings.hideCompletedItems);
@@ -71,10 +73,14 @@ const widgetController = {
{ modifiedOn: { $gte: startDate } }
];
} else {
- $match.status = { $eq: currentStatusSearch };
+ // never hide the completed items
+ $match.status = { $eq: SUGGESTION_STATUS.COMPLETED };
}
} else {
- $match.status = { $eq: currentStatusSearch };
+ $match['$or'] = [
+ { status: SUGGESTION_STATUS.BACKLOG },
+ { status: SUGGESTION_STATUS.INPROGRESS },
+ ];
}
switch (settings.defaultItemSorting) {
@@ -124,6 +130,23 @@ const widgetController = {
});
},
+ getFirstSuggestionsPage() {
+ return new Promise((resolve, reject) => {
+ this.getSuggestions().then((suggestions) => {
+ if (suggestions.length >= 10) {
+ resolve(suggestions);
+ } else {
+ state.isAllNotCompletedSuggestionFetched = true;
+ state.page = 0;
+
+ this.getSuggestions().then(() => {
+ resolve(state.suggestionsList);
+ });
+ }
+ })
+ })
+ },
+
getSuggestionById(suggestionId) {
return new Promise((resolve, reject) => {
Suggestions.getById(suggestionId).then((suggestion) => {
From f6a1050c49aecc4b953a33b17b90350de7435b49 Mon Sep 17 00:00:00 2001
From: alaa smadi
Date: Tue, 11 Mar 2025 04:25:56 +0300
Subject: [PATCH 2/9] feat(suggestions list): refactor suggestion vote icons
revert suggestion icon to use the old arrow up
---
widget/index.html | 12 ++++++------
widget/js/pages/home/index.js | 7 ++++++-
widget/js/pages/suggestion/index.js | 7 ++++++-
widget/js/pages/widgetPagesShared.js | 8 ++++----
4 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/widget/index.html b/widget/index.html
index 8a7baad..9fb7262 100755
--- a/widget/index.html
+++ b/widget/index.html
@@ -93,11 +93,11 @@
@@ -137,8 +137,8 @@
From 512d82d26fe71c6d7cfdf3ab1ff1b988470909c7 Mon Sep 17 00:00:00 2001
From: alaa smadi
Date: Wed, 12 Mar 2025 03:12:58 +0300
Subject: [PATCH 9/9] refactor fetching state variable
---
widget/js/pages/home/index.js | 4 ++--
widget/js/state.js | 2 +-
widget/js/widget.controller.js | 6 +++---
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/widget/js/pages/home/index.js b/widget/js/pages/home/index.js
index 0236b17..9754f9f 100644
--- a/widget/js/pages/home/index.js
+++ b/widget/js/pages/home/index.js
@@ -228,11 +228,11 @@ const homePage = {
});
if (suggestions.length < state.pageSize) {
- if (state.isAllNotCompletedSuggestionFetched) {
+ if (state.startFetchingCompleted) {
state.isAllSuggestionFetched = true;
if (!state.suggestionsList.length) this.printEmptyState();
} else {
- state.isAllNotCompletedSuggestionFetched = true;
+ state.startFetchingCompleted = true;
state.page = 0;
widgetController.getSuggestions().then((suggestions) => {
diff --git a/widget/js/state.js b/widget/js/state.js
index 4a16d0c..9306b23 100644
--- a/widget/js/state.js
+++ b/widget/js/state.js
@@ -53,7 +53,7 @@ const state = {
pageSize: 50,
fetching: false,
isAllSuggestionFetched: false,
- isAllNotCompletedSuggestionFetched: false,
+ startFetchingCompleted: false,
validUserImages: {},
suggestionsList: [],
updatedUsersData: [],
diff --git a/widget/js/widget.controller.js b/widget/js/widget.controller.js
index 47b27fe..b7b65d2 100644
--- a/widget/js/widget.controller.js
+++ b/widget/js/widget.controller.js
@@ -53,13 +53,13 @@ const widgetController = {
getSuggestions() {
return new Promise((resolve) => {
- const { page, pageSize, settings, isAllNotCompletedSuggestionFetched } = state;
+ const { page, pageSize, settings, startFetchingCompleted } = state;
const searchOptions = { page, pageSize };
let $match = {
"_buildfire.index.string1": { $exists: false }
}, $sort = {};
- if (isAllNotCompletedSuggestionFetched) {
+ if (startFetchingCompleted) {
// hide completed immediately
if (settings.hideCompletedItems === 0) return resolve([]);
@@ -136,7 +136,7 @@ const widgetController = {
if (suggestions.length >= 10) {
resolve(suggestions);
} else {
- state.isAllNotCompletedSuggestionFetched = true;
+ state.startFetchingCompleted = true;
state.page = 0;
this.getSuggestions().then(() => {