Skip to content

Commit 42d6dc8

Browse files
authored
fix: Advanced filters does not contain tags after first tag was added (@Rowan441) (#7025)
### Description fixes #6972 The setup logic for the "tags", "funbox", and "language" advanced filters are only run on the first load. So adding a tag in the /settings won't make the "tags" multiselect render when you navigate back to the /account page unless you reload. Added logic to add / destroy the "tags" multiselect if you create your first tag or delete your last tag. <!-- Please describe the change(s) made in your PR --> ### Checks - [ ] Adding quotes? - [ ] Make sure to include translations for the quotes in the description (or another comment) so we can verify their content. - [ ] Adding a language? - Make sure to follow the [languages documentation](https://github.com/monkeytypegame/monkeytype/blob/master/docs/LANGUAGES.md) - [ ] Add language to `packages/schemas/src/languages.ts` - [ ] Add language to exactly one group in `frontend/src/ts/constants/languages.ts` - [ ] Add language json file to `frontend/static/languages` - [ ] Adding a theme? - Make sure to follow the [themes documentation](https://github.com/monkeytypegame/monkeytype/blob/master/docs/THEMES.md) - [ ] Add theme to `packages/schemas/src/themes.ts` - [ ] Add theme to `frontend/src/ts/constants/themes.ts` - [ ] Add theme css file to `frontend/static/themes` - [ ] Add some screenshot of the theme, especially with different test settings (colorful, flip colors) to your pull request - [ ] Adding a layout? - [ ] Make sure to follow the [layouts documentation](https://github.com/monkeytypegame/monkeytype/blob/master/docs/LAYOUTS.md) - [ ] Add layout to `packages/schemas/src/layouts.ts` - [ ] Add layout json file to `frontend/static/layouts` - [ ] Adding a font? - Make sure to follow the [themes documentation](https://github.com/monkeytypegame/monkeytype/blob/master/docs/FONTS.md) - [ ] Add font file to `frontend/static/webfonts` - [ ] Add font to `packages/schemas/src/fonts.ts` - [ ] Add font to `frontend/src/ts/constants/fonts.ts` - [x] Check if any open issues are related to this PR; if so, be sure to tag them below. - [x] Make sure the PR title follows the Conventional Commits standard. (https://www.conventionalcommits.org for more info) - [x] Make sure to include your GitHub username prefixed with @ inside parentheses at the end of the PR title. <!-- label(optional scope): pull request title (@your_github_username) --> <!-- I know I know they seem boring but please do them, they help us and you will find out it also helps you.--> Closes #6972 <!-- the issue(s) your PR resolves if any (delete if that is not the case) --> <!-- please also reference any issues and or PRs related to your pull request --> <!-- Also remove it if you are not following any issues. --> <!-- pro tip: you can mention an issue, PR, or discussion on GitHub by referencing its hash number e.g: [#1234](#1234) --> <!-- pro tip: you can press . (dot or period) in the code tab of any GitHub repo to get access to GitHub's VS Code web editor Enjoy! :) -->
1 parent 05123e8 commit 42d6dc8

File tree

2 files changed

+45
-44
lines changed

2 files changed

+45
-44
lines changed

frontend/src/ts/elements/account/result-filters.ts

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -794,9 +794,14 @@ export function updateTagsDropdownOptions(): void {
794794

795795
let buttonsAppended = false;
796796

797-
export async function appendButtons(
797+
export async function appendDropdowns(
798798
selectChangeCallback: () => void
799799
): Promise<void> {
800+
//snapshot at this point is guaranteed to exist
801+
const snapshot = DB.getSnapshot() as Snapshot;
802+
803+
tagDropdownUpdate(snapshot);
804+
800805
if (buttonsAppended) return;
801806

802807
selectChangeCallbackFn = selectChangeCallback;
@@ -864,60 +869,58 @@ export async function appendButtons(
864869
},
865870
});
866871

867-
//snapshot at this point is guaranteed to exist
868-
const snapshot = DB.getSnapshot() as Snapshot;
872+
void updateFilterPresets();
873+
buttonsAppended = true;
874+
}
869875

876+
function tagDropdownUpdate(snapshot: Snapshot): void {
870877
const tagsSection = $(
871878
".pageAccount .content .filterButtons .buttonsAndTitle.tags"
872879
);
873880

874881
if (snapshot.tags.length === 0) {
875882
tagsSection.addClass("hidden");
883+
if (groupSelects["tags"]) {
884+
groupSelects["tags"].destroy();
885+
delete groupSelects["tags"];
886+
}
887+
setFilter("tags", "none", true);
876888
} else {
877889
tagsSection.removeClass("hidden");
890+
878891
updateTagsDropdownOptions();
879-
const selectEl = document.querySelector(
880-
".pageAccount .content .filterButtons .buttonsAndTitle.tags .select .tagsSelect"
881-
);
882-
if (selectEl) {
883-
groupSelects["tags"] = new SlimSelect({
884-
select: selectEl,
885-
settings: {
886-
showSearch: true,
887-
placeholderText: "select a tag",
888-
allowDeselect: true,
889-
closeOnSelect: false,
890-
},
891-
events: {
892-
beforeChange: (selectedOptions, oldSelectedOptions): boolean => {
893-
return selectBeforeChangeFn(
894-
"tags",
895-
selectedOptions,
896-
oldSelectedOptions
897-
);
892+
893+
// Only create SlimSelect if it doesn't exist yet
894+
if (!groupSelects["tags"]) {
895+
const selectEl = document.querySelector(
896+
".pageAccount .content .filterButtons .buttonsAndTitle.tags .select .tagsSelect"
897+
);
898+
899+
if (selectEl) {
900+
groupSelects["tags"] = new SlimSelect({
901+
select: selectEl,
902+
settings: {
903+
showSearch: true,
904+
placeholderText: "select a tag",
905+
allowDeselect: true,
906+
closeOnSelect: false,
898907
},
899-
beforeOpen: (): void => {
900-
adjustScrollposition("tags");
908+
events: {
909+
beforeChange: (selectedOptions, oldSelectedOptions): boolean => {
910+
return selectBeforeChangeFn(
911+
"tags",
912+
selectedOptions,
913+
oldSelectedOptions
914+
);
915+
},
916+
beforeOpen: (): void => {
917+
adjustScrollposition("tags");
918+
},
901919
},
902-
},
903-
});
920+
});
921+
}
904922
}
905923
}
906-
907-
void updateFilterPresets();
908-
buttonsAppended = true;
909-
}
910-
911-
export function removeButtons(): void {
912-
$(
913-
".pageAccount .content .filterButtons .buttonsAndTitle.languages .buttons"
914-
).empty();
915-
$(
916-
".pageAccount .content .filterButtons .buttonsAndTitle.funbox .buttons"
917-
).empty();
918-
$(
919-
".pageAccount .content .filterButtons .buttonsAndTitle.tags .buttons"
920-
).empty();
921924
}
922925

923926
$(".group.presetFilterButtons .filterBtns").on(

frontend/src/ts/pages/account.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,14 +1349,12 @@ export const page = new Page({
13491349
},
13501350
afterHide: async (): Promise<void> => {
13511351
reset();
1352-
ResultFilters.removeButtons();
13531352
Skeleton.remove("pageAccount");
13541353
},
13551354
beforeShow: async (): Promise<void> => {
13561355
Skeleton.append("pageAccount", "main");
13571356
const snapshot = DB.getSnapshot();
1358-
ResultFilters.updateTagsDropdownOptions();
1359-
await ResultFilters.appendButtons(update);
1357+
await ResultFilters.appendDropdowns(update);
13601358
ResultFilters.updateActive();
13611359
await Misc.sleep(0);
13621360

0 commit comments

Comments
 (0)