Skip to content

Commit 22305a5

Browse files
authored
feat: add no group found and search with prefix name (#835)
1 parent b22fca8 commit 22305a5

File tree

6 files changed

+84
-1
lines changed

6 files changed

+84
-1
lines changed

__tests__/groups/group.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,13 @@ describe('Discord Groups Page', () => {
257257

258258
expect(displayedGroups).toEqual(['First Daaa', 'DSA Coding Group']);
259259
});
260+
261+
test('Should display no group found div when no group is present', async () => {
262+
await page.goto(`${PAGE_URL}/groups?dev=true&name=no-group-present`);
263+
await page.waitForNetworkIdle();
264+
265+
const noGroupDiv = await page.$('.no-group-container');
266+
267+
expect(noGroupDiv).toBeTruthy();
268+
});
260269
});

groups/createElements.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ const createLoadingCard = () => {
5555
return cardElement;
5656
};
5757

58+
const createNoGroupFound = () => {
59+
const noGroupFound = document.createElement('div');
60+
noGroupFound.classList.add('no-group');
61+
noGroupFound.innerHTML = `
62+
<svg class="icon" fill=currentColor viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
63+
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"></path>
64+
</svg>
65+
<div class="message">
66+
<h2>No groups found</h2>
67+
<p>Please try a different search input</p>
68+
</div>
69+
`;
70+
71+
return noGroupFound;
72+
};
73+
5874
const createNavbarProfile = (profile) => {
5975
const profileElement = document.createElement('div');
6076
profileElement.className = 'profile';
@@ -201,6 +217,7 @@ const createGroupCreationModal = (onClose = () => {}, onSubmit = () => {}) => {
201217
export {
202218
createCard,
203219
createLoadingCard,
220+
createNoGroupFound,
204221
createNavbarProfile,
205222
createNavbarProfileLoading,
206223
createNavbarProfileSignin,

groups/render.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
createCard,
33
createGroupCreationModal,
44
createLoadingCard,
5+
createNoGroupFound,
56
createNavbarProfile,
67
createNavbarProfileLoading,
78
createNavbarProfileSignin,
@@ -96,6 +97,14 @@ const renderGroupById = ({ group, cardOnClick = () => {} }) => {
9697
}
9798
};
9899

100+
const renderNoGroupFound = () => {
101+
const mainContainer = document.querySelector('.group-container');
102+
const noGroupContainer = document.createElement('div');
103+
noGroupContainer.className = 'no-group-container';
104+
noGroupContainer.append(createNoGroupFound());
105+
mainContainer.append(noGroupContainer);
106+
};
107+
99108
export {
100109
renderNotAuthenticatedPage,
101110
renderGroupCreationModal,
@@ -107,4 +116,5 @@ export {
107116
renderLoadingCards,
108117
removeLoadingCards,
109118
renderGroupById,
119+
renderNoGroupFound,
110120
};

groups/script.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
renderGroupById,
77
renderGroupCreationModal,
88
renderLoadingCards,
9+
renderNoGroupFound,
910
renderLoadingNavbarProfile,
1011
renderNavbarProfile,
1112
renderNavbarProfileSignin,
@@ -60,6 +61,7 @@ const handler = {
6061
renderAllGroups({
6162
cardOnClick: groupCardOnAction,
6263
});
64+
if (isDev && (!value || value.length == 0)) renderNoGroupFound();
6365
break;
6466
case 'search':
6567
if (isDev) {

groups/style.css

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,51 @@ body {
404404
width: 3rem;
405405
}
406406

407+
.no-group-container {
408+
grid-column-start: 1;
409+
grid-column-end: 6;
410+
display: flex;
411+
justify-content: center;
412+
align-items: center;
413+
width: 100%;
414+
}
415+
416+
.no-group {
417+
display: flex;
418+
align-items: flex-start;
419+
max-width: 400px;
420+
width: 100%;
421+
padding: 1.5rem;
422+
background-color: var(--color-secondary-invert);
423+
border-left: 4px solid var(--color-secondary);
424+
border-radius: 4px;
425+
box-shadow: 0 2px 4px var(--color-list-border);
426+
427+
.icon {
428+
flex-shrink: 0;
429+
margin-right: 1rem;
430+
width: 24px;
431+
height: 24px;
432+
color: var(--color-secondary);
433+
}
434+
435+
.message {
436+
flex-grow: 1;
437+
}
438+
439+
.message h2 {
440+
margin: 0 0 0.5rem 0;
441+
font-size: 1.25rem;
442+
color: var(--color-secondary);
443+
}
444+
445+
.message p {
446+
margin: 0;
447+
font-size: 1rem;
448+
color: var(--color-secondary);
449+
}
450+
}
451+
407452
/*
408453
FOR Navbar
409454
*/

groups/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function getDiscordGroupIdsFromSearch(groups, multipleGroupSearch) {
134134
.map((group) => group.trim().toLowerCase());
135135
const matchGroups = groups.filter((group) =>
136136
searchGroups.some((searchGroup) =>
137-
group.title.toLowerCase().includes(searchGroup),
137+
group.title.toLowerCase().startsWith(searchGroup),
138138
),
139139
);
140140
return matchGroups.map((group) => group.id);

0 commit comments

Comments
 (0)