Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions scripts/smoke-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,14 @@ try {
await page.getByLabel('Complexity').selectOption('High');
await settle();
assert.equal(await page.locator('.list-row').count(), 2);
await page.getByLabel('Complexity').selectOption('Any');
await page.getByLabel('Bounty').selectOption('$250–$750');
await settle();
assert.equal(await page.locator('.list-row').count(), 3);
assert.equal(await page.getByRole('button', { name: /Filters/ }).locator('.pipcount').innerText(), '1');
await page.getByRole('button', { name: 'Reset' }).click();
await settle();
assert.equal(await page.getByLabel('Bounty').inputValue(), 'Any');
assert.equal(await page.locator('.list-row').count(), 7);

// ------------------------------------------------------- contributor apply
Expand Down
34 changes: 24 additions & 10 deletions src/pages/explore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ const TABS = [

const SORTS = ['Newest', 'Bounty', 'Title'] as const;
const LEVELS: (Complexity | 'Any')[] = ['Any', 'Trivial', 'Medium', 'High'];
const BOUNTIES = ['Any', 'Under $250', '$250–$750', 'Over $750'] as const;

export function Explore({ tab }: { tab: Tab }) {
const { state } = useApp();
const navigate = useNavigate();
const [params, setParams] = useSearchParams();
const [q, setQ] = useState(params.get('q') ?? '');
const [level, setLevel] = useState<Complexity | 'Any'>('Any');
const [bounty, setBounty] = useState<(typeof BOUNTIES)[number]>('Any');
const [lang, setLang] = useState('Any');
const [sort, setSort] = useState<(typeof SORTS)[number]>('Newest');
const [filtersOpen, setFiltersOpen] = useState(false);
Expand All @@ -50,14 +52,17 @@ export function Explore({ tab }: { tab: Tab }) {
const repo = accepted.find(r => r.id === issue.repoId);
if (!repo) return false;
if (level !== 'Any' && issue.complexity !== level) return false;
if (bounty === 'Under $250' && issue.bounty >= 250) return false;
if (bounty === '$250–$750' && (issue.bounty < 250 || issue.bounty > 750)) return false;
if (bounty === 'Over $750' && issue.bounty <= 750) return false;
if (lang !== 'Any' && !repo.languages.includes(lang)) return false;
return `${issue.title} ${issue.id} ${repoName(repo)}`.toLowerCase().includes(needle);
});
return list.sort((a, b) =>
sort === 'Bounty' ? b.bounty - a.bounty
: sort === 'Title' ? a.title.localeCompare(b.title)
: b.created.localeCompare(a.created));
}, [state.issues, accepted, level, lang, needle, sort]);
}, [state.issues, accepted, level, bounty, lang, needle, sort]);

const repos = useMemo(
() => accepted.filter(r =>
Expand All @@ -73,7 +78,7 @@ export function Explore({ tab }: { tab: Tab }) {
.map(o => ({ org: o, repos: accepted.filter(r => r.org === o) }));
}, [accepted, needle]);

const activeFilters = (level !== 'Any' ? 1 : 0) + (lang !== 'Any' ? 1 : 0);
const activeFilters = (level !== 'Any' ? 1 : 0) + (lang !== 'Any' ? 1 : 0) + (bounty !== 'Any' ? 1 : 0);
const count = tab === 'issues' ? issues.length : tab === 'repos' ? repos.length : orgs.length;

return (
Expand Down Expand Up @@ -132,13 +137,22 @@ export function Explore({ tab }: { tab: Tab }) {
>
<div className="filters-inner">
{tab === 'issues' && (
<label className="field inline">
<span>Complexity</span>
<select className="select" aria-label="Complexity" value={level}
onChange={e => setLevel(e.target.value as Complexity | 'Any')}>
{LEVELS.map(l => <option key={l}>{l}</option>)}
</select>
</label>
<>
<label className="field inline">
<span>Complexity</span>
<select className="select" aria-label="Complexity" value={level}
onChange={e => setLevel(e.target.value as Complexity | 'Any')}>
{LEVELS.map(l => <option key={l}>{l}</option>)}
</select>
</label>
<label className="field inline">
<span>Bounty</span>
<select className="select" aria-label="Bounty" value={bounty}
onChange={e => setBounty(e.target.value as (typeof BOUNTIES)[number])}>
{BOUNTIES.map(b => <option key={b}>{b}</option>)}
</select>
</label>
</>
)}
<label className="field inline">
<span>Language</span>
Expand All @@ -155,7 +169,7 @@ export function Explore({ tab }: { tab: Tab }) {
</select>
</label>
)}
<button className="btn sm ghost" onClick={() => { setLevel('Any'); setLang('Any'); setSort('Newest'); }}>
<button className="btn sm ghost" onClick={() => { setLevel('Any'); setBounty('Any'); setLang('Any'); setSort('Newest'); }}>
Reset
</button>
</div>
Expand Down