Compute and apply user-selected release channel in browse
This commit is contained in:
parent
d2cef996fd
commit
48880cb8a2
1 changed files with 16 additions and 8 deletions
|
|
@ -49,9 +49,9 @@ export default function RevengePluginsBrowseSettingScreen() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Let the user pick a release channel
|
/** The channel a listing displays: preferred, `latest`, else its first channel. */
|
||||||
/** The channel a listing displays: `latest`, else its first channel. */
|
function displayChannelOf(listing: RepoPluginListing, preferredChannel: string): string | undefined {
|
||||||
function displayChannelOf(listing: RepoPluginListing): string | undefined {
|
if (preferredChannel && listing.channels[preferredChannel]) return preferredChannel
|
||||||
if (listing.channels.latest) return 'latest'
|
if (listing.channels.latest) return 'latest'
|
||||||
return Object.keys(listing.channels)[0]
|
return Object.keys(listing.channels)[0]
|
||||||
}
|
}
|
||||||
|
|
@ -82,15 +82,18 @@ function Screen() {
|
||||||
const [excluded, setExcluded] = useState<string[]>([])
|
const [excluded, setExcluded] = useState<string[]>([])
|
||||||
const [sort, setSort] = useState<BrowseSortKey>('name')
|
const [sort, setSort] = useState<BrowseSortKey>('name')
|
||||||
const [reverse, setReverse] = useState(false)
|
const [reverse, setReverse] = useState(false)
|
||||||
|
const [channel, setChannel] = useState('')
|
||||||
|
const [channels, setChannels] = useState<string[]>([])
|
||||||
|
|
||||||
const hasFilter = useMemo(
|
const hasFilter = useMemo(
|
||||||
() => excluded.length > 0 || sort !== 'name' || reverse,
|
() => excluded.length > 0 || sort !== 'name' || reverse || channel !== '',
|
||||||
[excluded, sort, reverse],
|
[excluded, sort, reverse, channel],
|
||||||
)
|
)
|
||||||
|
|
||||||
const load = useCallback(async () => {
|
const load = useCallback(async () => {
|
||||||
const repos = await listRepos()
|
const repos = await listRepos()
|
||||||
const all: BrowseEntry[] = []
|
const all: BrowseEntry[] = []
|
||||||
|
const allChannels = new Set<string>()
|
||||||
|
|
||||||
setInternalRepos(
|
setInternalRepos(
|
||||||
repos.filter(repo => repo.internal).map(repo => repo.url),
|
repos.filter(repo => repo.internal).map(repo => repo.url),
|
||||||
|
|
@ -108,7 +111,9 @@ function Screen() {
|
||||||
|
|
||||||
for (const listing of listings) {
|
for (const listing of listings) {
|
||||||
const plugin = pList.get(listing.id)
|
const plugin = pList.get(listing.id)
|
||||||
const displayChannel = displayChannelOf(listing)
|
for (const c of Object.keys(listing.channels))
|
||||||
|
allChannels.add(c)
|
||||||
|
const displayChannel = displayChannelOf(listing, channel)
|
||||||
const displayVersion = displayChannel
|
const displayVersion = displayChannel
|
||||||
? (listing.channels[displayChannel] ?? '')
|
? (listing.channels[displayChannel] ?? '')
|
||||||
: ''
|
: ''
|
||||||
|
|
@ -119,7 +124,6 @@ function Screen() {
|
||||||
repoName: repo.name ?? null,
|
repoName: repo.name ?? null,
|
||||||
repositoryText,
|
repositoryText,
|
||||||
version: displayVersion,
|
version: displayVersion,
|
||||||
// TODO: Let the user pick a release channel
|
|
||||||
channel: displayChannel,
|
channel: displayChannel,
|
||||||
size:
|
size:
|
||||||
listing.versions[displayVersion]
|
listing.versions[displayVersion]
|
||||||
|
|
@ -139,8 +143,9 @@ function Screen() {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
setChannels([...allChannels].sort())
|
||||||
setEntries(all)
|
setEntries(all)
|
||||||
}, [])
|
}, [channel, setChannels])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Show cached indexes right away, then refresh everything
|
// Show cached indexes right away, then refresh everything
|
||||||
|
|
@ -234,6 +239,9 @@ function Screen() {
|
||||||
.map(repo => repo.url)
|
.map(repo => repo.url)
|
||||||
.filter(url => !urls.includes(url)),
|
.filter(url => !urls.includes(url)),
|
||||||
),
|
),
|
||||||
|
channels,
|
||||||
|
channel,
|
||||||
|
setChannel,
|
||||||
sort,
|
sort,
|
||||||
setSort,
|
setSort,
|
||||||
reverse,
|
reverse,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue