🏡 index : ~doyle/chartered.git

author Jordan Doyle <jordan@doyle.la> 2021-10-09 3:55:09.0 +01:00:00
committer Jordan Doyle <jordan@doyle.la> 2021-10-09 3:55:09.0 +01:00:00
commit
1916f2b8ae1f7cdb3eadc351e2e7e199126d4922 [patch]
tree
54ac34dbed5df71b760262699ef1cc0364d61e3d
parent
9065b8577942e3c732e85b1782785cbe87173442
download
1916f2b8ae1f7cdb3eadc351e2e7e199126d4922.tar.gz

Search by any alias in member search



Diff

 chartered-db/src/users.rs                           | 11 +++++++++++
 chartered-frontend/src/pages/crate/Members.tsx      | 11 ++++++++---
 chartered-web/src/endpoints/web_api/users/search.rs |  6 ++++--
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/chartered-db/src/users.rs b/chartered-db/src/users.rs
index 62a1cc0..945b5b5 100644
--- a/chartered-db/src/users.rs
+++ a/chartered-db/src/users.rs
@@ -28,13 +28,20 @@
        given_query: String,
        limit: i64,
    ) -> Result<Vec<User>> {
        use crate::schema::users::dsl::username;
        use crate::schema::users::dsl::{name, nick, username};

        tokio::task::spawn_blocking(move || {
            let conn = conn.get()?;

            let query = format!("%{}%", given_query);

            Ok(crate::schema::users::table
                .filter(username.like(format!("%{}%", given_query)))
                .filter(
                    username
                        .like(&query)
                        .or(name.like(&query))
                        .or(nick.like(&query)),
                )
                .limit(limit)
                .load(&conn)?)
        })
diff --git a/chartered-frontend/src/pages/crate/Members.tsx b/chartered-frontend/src/pages/crate/Members.tsx
index 36805a8..4e2463e 100644
--- a/chartered-frontend/src/pages/crate/Members.tsx
+++ a/chartered-frontend/src/pages/crate/Members.tsx
@@ -83,12 +83,13 @@

        {possiblePermissions ? (
          <MemberListInserter
            onInsert={(username, userUuid) =>
            onInsert={(displayName, pictureUrl, userUuid) =>
              setProspectiveMembers([
                ...prospectiveMembers,
                {
                  uuid: userUuid,
                  username,
                  display_name: displayName,
                  picture_url: pictureUrl,
                  permissions: ["VISIBLE"],
                },
              ])
@@ -257,7 +258,7 @@
  existingMembers,
}: {
  existingMembers: Member[];
  onInsert: (username, user_uuid) => any;
  onInsert: (username, picture_url, user_uuid) => any;
}) {
  const auth = useAuth();
  const searchRef = React.useRef(null);
@@ -291,7 +292,7 @@
  };

  const handleChange = (selected) => {
    onInsert(selected[0].username, selected[0].user_uuid);
    onInsert(selected[0].display_name, selected[0].picture_url, selected[0].user_uuid);
    searchRef.current.clear();
  };

@@ -321,7 +322,7 @@
              (existing) => option.user_uuid === existing.uuid
            ) === -1
          }
          labelKey="username"
          labelKey="display_name"
          options={options}
          isLoading={loading}
          placeholder="Search for User"
diff --git a/chartered-web/src/endpoints/web_api/users/search.rs b/chartered-web/src/endpoints/web_api/users/search.rs
index b422beb..a940f38 100644
--- a/chartered-web/src/endpoints/web_api/users/search.rs
+++ a/chartered-web/src/endpoints/web_api/users/search.rs
@@ -16,7 +16,8 @@
#[derive(Serialize)]
pub struct ResponseUser {
    user_uuid: chartered_db::uuid::Uuid,
    username: String,
    display_name: String,
    picture_url: Option<String>,
}

pub async fn handle(
@@ -28,7 +29,8 @@
        .into_iter()
        .map(|user| ResponseUser {
            user_uuid: user.uuid.0,
            username: user.username,
            display_name: user.display_name().to_string(),
            picture_url: user.picture_url,
        })
        .collect();