From 45e54789b72e8402cecc86e1d1764bdef2a51c69 Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Tue, 6 Sep 2022 15:51:36 -0600 Subject: [PATCH] Groups search shares query, sorted by contract & members --- web/components/groups/group-selector.tsx | 14 ++++++++++---- web/pages/groups.tsx | 23 +++++++---------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/web/components/groups/group-selector.tsx b/web/components/groups/group-selector.tsx index 344339d1..a75a0a34 100644 --- a/web/components/groups/group-selector.tsx +++ b/web/components/groups/group-selector.tsx @@ -9,7 +9,7 @@ import { import clsx from 'clsx' import { CreateGroupButton } from 'web/components/groups/create-group-button' import { useState } from 'react' -import { useMemberGroups } from 'web/hooks/use-group' +import { useMemberGroups, useOpenGroups } from 'web/hooks/use-group' import { User } from 'common/user' import { searchInAny } from 'common/util/parse' @@ -27,9 +27,15 @@ export function GroupSelector(props: { const [isCreatingNewGroup, setIsCreatingNewGroup] = useState(false) const { showSelector, showLabel, ignoreGroupIds } = options const [query, setQuery] = useState('') - const availableGroups = (useMemberGroups(creator?.id) ?? []).filter( - (group) => !ignoreGroupIds?.includes(group.id) - ) + const openGroups = useOpenGroups() + const availableGroups = openGroups + .concat( + (useMemberGroups(creator?.id) ?? []).filter( + (g) => !openGroups.map((og) => og.id).includes(g.id) + ) + ) + .filter((group) => !ignoreGroupIds?.includes(group.id)) + const filteredGroups = availableGroups.filter((group) => searchInAny(query, group.name) ) diff --git a/web/pages/groups.tsx b/web/pages/groups.tsx index 3405ef3e..f39a7647 100644 --- a/web/pages/groups.tsx +++ b/web/pages/groups.tsx @@ -65,20 +65,9 @@ export default function Groups(props: { const [query, setQuery] = useState('') - // List groups with the highest question count, then highest member count - // TODO use find-active-contracts to sort by? - const matches = sortBy(groups, []).filter((g) => - searchInAny( - query, - g.name, - g.about || '', - creatorsDict[g.creatorId].username - ) - ) - - const matchesOrderedByRecentActivity = sortBy(groups, [ - (group) => - -1 * (group.mostRecentContractAddedTime ?? group.mostRecentActivityTime), + const matchesOrderedByMostContractAndMembers = sortBy(groups, [ + (group) => -1 * group.totalContracts, + (group) => -1 * group.totalMembers, ]).filter((g) => searchInAny( query, @@ -120,13 +109,14 @@ export default function Groups(props: { debouncedQuery(e.target.value)} placeholder="Search your groups" className="input input-bordered mb-4 w-full" />
- {matchesOrderedByRecentActivity + {matchesOrderedByMostContractAndMembers .filter((match) => memberGroupIds.includes(match.id) ) @@ -153,11 +143,12 @@ export default function Groups(props: { type="text" onChange={(e) => debouncedQuery(e.target.value)} placeholder="Search groups" + value={query} className="input input-bordered mb-4 w-full" />
- {matches.map((group) => ( + {matchesOrderedByMostContractAndMembers.map((group) => (