diff options
author | Daniel Schadt <kingdread@gmx.de> | 2023-06-19 19:48:16 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2023-06-19 19:48:16 +0200 |
commit | 4ca35b938e6ccd07e47b04869fbe30e9109bcbe4 (patch) | |
tree | 92f9037ef03aa6794358800006415b4da0ec6072 /asset-sources | |
parent | 772d5fd95077cced5de160b17adc1415d31a6791 (diff) | |
download | fietsboek-4ca35b938e6ccd07e47b04869fbe30e9109bcbe4.tar.gz fietsboek-4ca35b938e6ccd07e47b04869fbe30e9109bcbe4.tar.bz2 fietsboek-4ca35b938e6ccd07e47b04869fbe30e9109bcbe4.zip |
hide friends that are already tagged
Diffstat (limited to 'asset-sources')
-rw-r--r-- | asset-sources/fietsboek.ts | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/asset-sources/fietsboek.ts b/asset-sources/fietsboek.ts index 1cadfc2..b885271 100644 --- a/asset-sources/fietsboek.ts +++ b/asset-sources/fietsboek.ts @@ -138,6 +138,23 @@ function checkNameValidity(name: Selector) { checkNameValidity; /** + * Check whether the given friend is already tagged. + * + * Note that this uses the "HTML list", so it uses the tags that the user is + * currently editing - not the ones from the database! + * + * @param friendId - ID of the friend to check. + * @return Whether the friend is in the list of tagged people. + */ +function friendIsTagged(friendId: number): boolean { + return Array.from(document.querySelectorAll("[name='tagged-friend[]']")) + .map((obj) => obj as HTMLInputElement) + .filter((obj) => !obj.disabled) + .map((obj) => obj.value) + .includes(friendId.toString()); +} + +/** * Hit the endpoint to search for friends. This populates the friend selector * when tagging friends. */ @@ -152,10 +169,15 @@ function searchFriends() { const blueprint = document.querySelector("#friendSearchBlueprint") as HTMLLIElement; // Only show friends with a matching name - const friends = response.filter( + let friends = response.filter( (obj) => obj.name.toLowerCase().indexOf(searchPattern) != -1 ); + // Only show friends that are not yet existing + friends = friends.filter( + (obj) => !friendIsTagged(obj.id) + ); + friends.forEach((friend) => { const copy = blueprint.cloneNode(true) as HTMLLIElement; copy.removeAttribute("id"); |