aboutsummaryrefslogtreecommitdiff
path: root/asset-sources/fietsboek.ts
diff options
context:
space:
mode:
Diffstat (limited to 'asset-sources/fietsboek.ts')
-rw-r--r--asset-sources/fietsboek.ts24
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");