diff options
Diffstat (limited to 'source/features')
-rw-r--r-- | source/features/global-discussion-list-filters.tsx | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/source/features/global-discussion-list-filters.tsx b/source/features/global-discussion-list-filters.tsx index 1b4510b3..6d1473db 100644 --- a/source/features/global-discussion-list-filters.tsx +++ b/source/features/global-discussion-list-filters.tsx @@ -5,7 +5,10 @@ import {getUsername} from '../libs/utils'; function init() { const defaultQuery = 'is:open archived:false '; - const type = location.pathname === '/issues' ? ' is:issues' : ''; // Without this, the Issues page also displays PRs + + // Without this, the Issues page also displays PRs, and viceversa + const type = location.pathname === '/issues' ? 'is:issue ' : 'is:pr '; + const links = [ ['Commented', `commenter:${getUsername()}`], ['Yours', `user:${getUsername()}`] @@ -13,12 +16,12 @@ function init() { for (const [label, query] of links) { // Create link - const url = new URLSearchParams([['q', defaultQuery + query + type]]); - const link = <a href={`?${url}`} className="subnav-item">{label}</a>; + const url = new URLSearchParams([['q', type + defaultQuery + query]]); + const link = <a href={`${location.pathname}?${url}`} className="subnav-item">{label}</a>; - // Create regex for current query, including possible spaces around it, to drop it in .replace() - const queryRegex = new RegExp(`(^|\\s)?${query}(\\s|$)?`); - const isCurrentPage = queryRegex.test(new URLSearchParams(location.search).get('q')!); + const isCurrentPage = new RegExp(`(^|\\s)${query}(\\s|$)`).test( + new URLSearchParams(location.search).get('q')! + ); // Highlight it, if that's the current page if (isCurrentPage && !select.exists('.subnav-links .selected')) { @@ -27,7 +30,7 @@ function init() { // Other links will keep the current query, that's not what we want for (const otherLink of select.all<HTMLAnchorElement>('.subnav-links a')) { const search = new URLSearchParams(otherLink.search); - search.set('q', search.get('q')!.replace(queryRegex, '')); + search.set('q', search.get('q')!.split(' ').filter(s => s !== query).join(' ')); otherLink.search = String(search); } } |