Skip to content

Commit 4194dba

Browse files
authored
Add bounty allocation filter (#593)
1 parent eaa8a3e commit 4194dba

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

apps/events/src/routes/bounties.lazy.tsx

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,47 @@
11
import { useEntities } from '@graphprotocol/hypergraph-react';
22
import { createLazyFileRoute } from '@tanstack/react-router';
3+
import { useState } from 'react';
34
import { Bounty } from '@/schema';
45

56
export const Route = createLazyFileRoute('/bounties')({
67
component: RouteComponent,
78
});
89

9-
const PERSON_ENTITY_ID = '7728d2458ae842d3a90a37e0bb8ee676';
10+
type AllocationFilter = 'all' | 'allocated' | 'unallocated';
1011

1112
function RouteComponent() {
13+
const [allocationFilter, setAllocationFilter] = useState<AllocationFilter>('all');
14+
const filter = allocationFilter === 'all' ? undefined : { allocated: { exists: allocationFilter === 'allocated' } };
15+
1216
const {
1317
data: bounties,
1418
isLoading,
1519
isError,
1620
} = useEntities(Bounty, {
1721
mode: 'public',
1822
spaces: 'all',
19-
filter: {
20-
interestedIn: { entityId: PERSON_ENTITY_ID },
23+
filter,
24+
include: {
25+
allocated: {},
2126
},
2227
});
2328

2429
return (
2530
<div className="flex flex-col gap-4 max-w-(--breakpoint-sm) mx-auto py-8">
2631
<h1 className="text-2xl font-bold">Bounties</h1>
27-
<p className="text-sm text-gray-500">Bounties where person {PERSON_ENTITY_ID} expressed interest</p>
32+
<p className="text-sm text-gray-500">Filter bounties by allocation status</p>
33+
<label className="text-sm text-gray-700 flex flex-col gap-1">
34+
Allocation status
35+
<select
36+
className="border rounded px-2 py-1 bg-white"
37+
value={allocationFilter}
38+
onChange={(event) => setAllocationFilter(event.target.value as AllocationFilter)}
39+
>
40+
<option value="all">All</option>
41+
<option value="allocated">Allocated (at least one person)</option>
42+
<option value="unallocated">Unallocated (no one)</option>
43+
</select>
44+
</label>
2845

2946
{isLoading && <div>Loading...</div>}
3047
{isError && <div>Error loading bounties</div>}
@@ -35,8 +52,11 @@ function RouteComponent() {
3552
{bounties.map((bounty) => (
3653
<li key={bounty.id} className="border rounded p-4">
3754
<h2 className="font-semibold">{bounty.name}</h2>
38-
{bounty.description && <p className="text-sm text-gray-600">{bounty.description}</p>}
55+
{bounty.description && <p className="text-sm text-gray-600">{bounty.description.substring(0, 100)}...</p>}
3956
<p className="text-xs text-gray-400 mt-1">{bounty.id}</p>
57+
<p className="text-xs text-gray-400 mt-1">
58+
Allocated to: {bounty.allocated.map((allocated) => allocated.name).join(', ')}
59+
</p>
4060
</li>
4161
))}
4262
</ul>

apps/events/src/schema.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,18 +372,22 @@ export const PersonBacklink = Entity.Schema(
372372
},
373373
);
374374

375+
export const ALLOCATED_PROPERTY_ID = Id('cfeb642223c54df4b3f9375a489d9e22');
376+
375377
export const Bounty = Entity.Schema(
376378
{
377379
name: Type.String,
378380
description: Type.optional(Type.String),
379381
interestedIn: Type.Backlink(PersonBacklink),
382+
allocated: Type.Relation(PersonBacklink),
380383
},
381384
{
382385
types: [Id('808af0bad5884e3391f09dd4b25e18be')],
383386
properties: {
384387
name: Id(SystemIds.NAME_PROPERTY),
385388
description: Id(SystemIds.DESCRIPTION_PROPERTY),
386389
interestedIn: Id('ff7e1b4444a2419187324e6c222afe07'),
390+
allocated: ALLOCATED_PROPERTY_ID,
387391
},
388392
},
389393
);

0 commit comments

Comments
 (0)