Skip to content

Commit dfe33f2

Browse files
Merge pull request #818 from Real-Dev-Squad/feat/groups/sharable-link
feat: add multiple discord groups sharable link
2 parents b49b579 + fcf5837 commit dfe33f2

File tree

4 files changed

+69
-15
lines changed

4 files changed

+69
-15
lines changed

__tests__/groups/group.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,18 @@ describe('Discord Groups Page', () => {
243243

244244
expect(groupCreationModalClosed).toBeFalsy();
245245
});
246+
247+
test('Should display only specified groups when dev=true and name=<group-name> with different case', async () => {
248+
const groupNames = 'fIrSt,DSA+COdInG';
249+
await page.goto(`${PAGE_URL}/groups?dev=true&name=${groupNames}`);
250+
await page.waitForNetworkIdle();
251+
252+
const displayedGroups = await page.evaluate(() => {
253+
return Array.from(document.querySelectorAll('.card__title')).map(
254+
(el) => el.textContent,
255+
);
256+
});
257+
258+
expect(displayedGroups).toEqual(['First Daaa', 'DSA Coding Group']);
259+
});
246260
});

groups/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
</div>
3838
<div class="create-group">
3939
<button class="button">
40-
<span class="button__text">Create grp</span>
40+
<span class="button__text">Create Group</span>
4141
<img src="assets/plus.svg" class="button__icon" />
4242
</button>
4343
</div>

groups/script.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,17 @@ import {
1818
getUserGroupRoles,
1919
getUserSelf,
2020
removeRoleFromMember,
21+
getDiscordGroupIdsFromSearch,
22+
getParamValueFromURL,
23+
setParamValueInURL,
2124
} from './utils.js';
2225

26+
const QUERY_PARAM_KEY = {
27+
DEV_FEATURE_FLAG: 'dev',
28+
GROUP_SEARCH: 'name',
29+
};
30+
const isDev = getParamValueFromURL(QUERY_PARAM_KEY.DEV_FEATURE_FLAG) === 'true';
31+
2332
const handler = {
2433
set: (obj, prop, value) => {
2534
switch (prop) {
@@ -53,7 +62,13 @@ const handler = {
5362
});
5463
break;
5564
case 'search':
56-
if (value === '') {
65+
if (isDev) {
66+
setParamValueInURL(QUERY_PARAM_KEY.GROUP_SEARCH, value);
67+
dataStore.filteredGroupsIds = getDiscordGroupIdsFromSearch(
68+
Object.values(dataStore.groups),
69+
value,
70+
);
71+
} else if (value === '') {
5772
if (dataStore.groups == null) break;
5873
dataStore.filteredGroupsIds = Object.values(dataStore.groups).map(
5974
(group) => group.id,
@@ -107,7 +122,7 @@ const dataStore = new Proxy(
107122
userSelf: null,
108123
groups: null,
109124
filteredGroupsIds: null,
110-
search: '',
125+
search: isDev ? getParamValueFromURL(QUERY_PARAM_KEY.GROUP_SEARCH) : '',
111126
discordId: null,
112127
isCreateGroupModalOpen: false,
113128
},
@@ -171,6 +186,12 @@ const afterAuthentication = async () => {
171186
};
172187
return acc;
173188
}, {});
189+
if (isDev) {
190+
dataStore.filteredGroupsIds = getDiscordGroupIdsFromSearch(
191+
Object.values(dataStore.groups),
192+
dataStore.search,
193+
);
194+
}
174195
dataStore.discordId = roleData.userId;
175196
},
176197
);
@@ -188,6 +209,7 @@ const bindGroupCreationButton = () => {
188209

189210
const bindSearchInput = () => {
190211
const searchInput = document.querySelector('.search__input');
212+
if (isDev) searchInput.value = dataStore.search;
191213
searchInput.addEventListener('input', (e) => {
192214
dataStore.search = e.target.value;
193215
});

groups/utils.js

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,36 @@ function removeGroupKeywordFromDiscordRoleName(groupName) {
126126
return groupName;
127127
}
128128

129-
//Function to parse only search value from URL
130-
function getSearchValueFromURL() {
131-
const params = new URLSearchParams(window.location.search);
129+
function getDiscordGroupIdsFromSearch(groups, multipleGroupSearch) {
130+
if (!multipleGroupSearch) return groups.map((group) => group.id);
131+
const GROUP_SEARCH_SEPARATOR = ',';
132+
const searchGroups = multipleGroupSearch
133+
.split(GROUP_SEARCH_SEPARATOR)
134+
.map((group) => group.trim().toLowerCase());
135+
const matchGroups = groups.filter((group) =>
136+
searchGroups.some((searchGroup) =>
137+
group.title.toLowerCase().includes(searchGroup),
138+
),
139+
);
140+
return matchGroups.map((group) => group.id);
141+
}
132142

133-
let searchValue = null;
143+
function getParamValueFromURL(paramKey) {
144+
const params = new URLSearchParams(window.location.search);
145+
return params.get(paramKey);
146+
}
134147

135-
for (const [key, value] of params.entries()) {
136-
if (value === '') {
137-
searchValue = key;
138-
break;
139-
}
140-
}
141-
return searchValue;
148+
function setParamValueInURL(paramKey, paramValue) {
149+
const params = new URLSearchParams(window.location.search);
150+
if (paramValue === '') params.delete(paramKey);
151+
else params.set(paramKey, paramValue);
152+
window.history.replaceState(
153+
{},
154+
'',
155+
window.location.pathname + (params.toString() && `?${params}`),
156+
);
142157
}
158+
143159
export {
144160
getUserGroupRoles,
145161
getMembers,
@@ -149,5 +165,7 @@ export {
149165
addGroupRoleToMember,
150166
removeRoleFromMember,
151167
removeGroupKeywordFromDiscordRoleName,
152-
getSearchValueFromURL,
168+
getDiscordGroupIdsFromSearch,
169+
getParamValueFromURL,
170+
setParamValueInURL,
153171
};

0 commit comments

Comments
 (0)