mirror of
https://github.com/colanode/colanode.git
synced 2025-12-28 16:06:37 +01:00
Small improvements
This commit is contained in:
@@ -18,16 +18,10 @@ export class UserSearchQueryHandler
|
||||
public async handleQuery(
|
||||
input: UserSearchQueryInput,
|
||||
): Promise<QueryResult<UserSearchQueryInput>> {
|
||||
if (input.searchQuery.length === 0) {
|
||||
return {
|
||||
output: [],
|
||||
state: {
|
||||
rows: [],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const rows = await this.fetchNodes(input);
|
||||
const rows =
|
||||
input.searchQuery.length > 0
|
||||
? await this.searchUsers(input)
|
||||
: await this.fetchUsers(input);
|
||||
return {
|
||||
output: this.buildUserNodes(rows),
|
||||
state: {
|
||||
@@ -54,7 +48,11 @@ export class UserSearchQueryHandler
|
||||
};
|
||||
}
|
||||
|
||||
const rows = await this.fetchNodes(input);
|
||||
const rows =
|
||||
input.searchQuery.length > 0
|
||||
? await this.searchUsers(input)
|
||||
: await this.fetchUsers(input);
|
||||
|
||||
if (isEqual(rows, state.rows)) {
|
||||
return {
|
||||
hasChanges: false,
|
||||
@@ -72,7 +70,9 @@ export class UserSearchQueryHandler
|
||||
};
|
||||
}
|
||||
|
||||
private async fetchNodes(input: UserSearchQueryInput): Promise<SelectNode[]> {
|
||||
private async searchUsers(
|
||||
input: UserSearchQueryInput,
|
||||
): Promise<SelectNode[]> {
|
||||
const workspaceDatabase = await databaseManager.getWorkspaceDatabase(
|
||||
input.userId,
|
||||
);
|
||||
@@ -90,6 +90,19 @@ export class UserSearchQueryHandler
|
||||
return result.rows;
|
||||
}
|
||||
|
||||
private async fetchUsers(input: UserSearchQueryInput): Promise<SelectNode[]> {
|
||||
const workspaceDatabase = await databaseManager.getWorkspaceDatabase(
|
||||
input.userId,
|
||||
);
|
||||
|
||||
return workspaceDatabase
|
||||
.selectFrom('nodes')
|
||||
.where('type', '=', NodeTypes.User)
|
||||
.where('id', '!=', input.userId)
|
||||
.selectAll()
|
||||
.execute();
|
||||
}
|
||||
|
||||
private buildUserNodes = (rows: SelectNode[]): UserNode[] => {
|
||||
return rows.map((row) => {
|
||||
const attributes = JSON.parse(row.attributes);
|
||||
|
||||
@@ -80,6 +80,10 @@ export const WorkspaceUserInvite = () => {
|
||||
emails: emails,
|
||||
userId: workspace.userId,
|
||||
},
|
||||
onSuccess() {
|
||||
setEmails([]);
|
||||
setInput('');
|
||||
},
|
||||
onError() {
|
||||
toast({
|
||||
title: 'Failed to invite users',
|
||||
|
||||
Reference in New Issue
Block a user