Groups search shares query, sorted by contract & members

This commit is contained in:
Ian Philips 2022-09-06 15:51:36 -06:00
parent c59de1be2e
commit 45e54789b7
2 changed files with 17 additions and 20 deletions

View File

@ -9,7 +9,7 @@ import {
import clsx from 'clsx' import clsx from 'clsx'
import { CreateGroupButton } from 'web/components/groups/create-group-button' import { CreateGroupButton } from 'web/components/groups/create-group-button'
import { useState } from 'react' 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 { User } from 'common/user'
import { searchInAny } from 'common/util/parse' import { searchInAny } from 'common/util/parse'
@ -27,9 +27,15 @@ export function GroupSelector(props: {
const [isCreatingNewGroup, setIsCreatingNewGroup] = useState(false) const [isCreatingNewGroup, setIsCreatingNewGroup] = useState(false)
const { showSelector, showLabel, ignoreGroupIds } = options const { showSelector, showLabel, ignoreGroupIds } = options
const [query, setQuery] = useState('') const [query, setQuery] = useState('')
const availableGroups = (useMemberGroups(creator?.id) ?? []).filter( const openGroups = useOpenGroups()
(group) => !ignoreGroupIds?.includes(group.id) 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) => const filteredGroups = availableGroups.filter((group) =>
searchInAny(query, group.name) searchInAny(query, group.name)
) )

View File

@ -65,20 +65,9 @@ export default function Groups(props: {
const [query, setQuery] = useState('') const [query, setQuery] = useState('')
// List groups with the highest question count, then highest member count const matchesOrderedByMostContractAndMembers = sortBy(groups, [
// TODO use find-active-contracts to sort by? (group) => -1 * group.totalContracts,
const matches = sortBy(groups, []).filter((g) => (group) => -1 * group.totalMembers,
searchInAny(
query,
g.name,
g.about || '',
creatorsDict[g.creatorId].username
)
)
const matchesOrderedByRecentActivity = sortBy(groups, [
(group) =>
-1 * (group.mostRecentContractAddedTime ?? group.mostRecentActivityTime),
]).filter((g) => ]).filter((g) =>
searchInAny( searchInAny(
query, query,
@ -120,13 +109,14 @@ export default function Groups(props: {
<Col> <Col>
<input <input
type="text" type="text"
value={query}
onChange={(e) => debouncedQuery(e.target.value)} onChange={(e) => debouncedQuery(e.target.value)}
placeholder="Search your groups" placeholder="Search your groups"
className="input input-bordered mb-4 w-full" className="input input-bordered mb-4 w-full"
/> />
<div className="flex flex-wrap justify-center gap-4"> <div className="flex flex-wrap justify-center gap-4">
{matchesOrderedByRecentActivity {matchesOrderedByMostContractAndMembers
.filter((match) => .filter((match) =>
memberGroupIds.includes(match.id) memberGroupIds.includes(match.id)
) )
@ -153,11 +143,12 @@ export default function Groups(props: {
type="text" type="text"
onChange={(e) => debouncedQuery(e.target.value)} onChange={(e) => debouncedQuery(e.target.value)}
placeholder="Search groups" placeholder="Search groups"
value={query}
className="input input-bordered mb-4 w-full" className="input input-bordered mb-4 w-full"
/> />
<div className="flex flex-wrap justify-center gap-4"> <div className="flex flex-wrap justify-center gap-4">
{matches.map((group) => ( {matchesOrderedByMostContractAndMembers.map((group) => (
<GroupCard <GroupCard
key={group.id} key={group.id}
group={group} group={group}