mirror of
https://github.com/modrinth/code.git
synced 2026-08-27 10:04:52 +00:00
fix: download threshold (#6242)
* fix: download threshold * fix: download threshold for projects select * refactor: pnpm prepr * feat: handle facets not adding count * feat: remove getting facets download count field entirely * feat: update facets to match new backend shape
This commit is contained in:
@@ -232,7 +232,13 @@ import {
|
||||
type AnalyticsFilterValueCategory = Exclude<AnalyticsQueryFilterCategory, 'project'>
|
||||
type GameVersionType = 'release' | 'all'
|
||||
type SetDropdownFilterValues = (values: string[]) => void
|
||||
type ApplyDownloadsThreshold = (setSelectedValues: SetDropdownFilterValues) => void
|
||||
type DownloadsThresholdSelection = {
|
||||
categoryKey: DownloadsThresholdFilterCategory
|
||||
selectedValues: string[]
|
||||
}
|
||||
type ApplyDownloadsThreshold = (
|
||||
setSelectedValues: SetDropdownFilterValues,
|
||||
) => DownloadsThresholdSelection | null
|
||||
type CloseDownloadsThresholdMenu = (event?: Event) => void
|
||||
|
||||
const props = withDefaults(
|
||||
@@ -763,48 +769,46 @@ function compareOptionalDateStringsDescending(
|
||||
function applyGameVersionDownloadsThreshold(setSelectedValues: SetDropdownFilterValues) {
|
||||
const threshold = gameVersionDownloadsThreshold.value
|
||||
if (threshold === null) {
|
||||
return
|
||||
return null
|
||||
}
|
||||
|
||||
const selectedValues = gameVersionFilterOptions.value
|
||||
.filter((gameVersion) => {
|
||||
return (gameVersionDownloadsByVersion.value.get(gameVersion.value) ?? 0) >= threshold
|
||||
return (gameVersionDownloadsByVersion.value.get(gameVersion.value) ?? 0) > threshold
|
||||
})
|
||||
.map((gameVersion) => gameVersion.value)
|
||||
|
||||
setDownloadsThresholdSelectedValues('game_version', selectedValues, setSelectedValues)
|
||||
return setDownloadsThresholdSelectedValues('game_version', selectedValues, setSelectedValues)
|
||||
}
|
||||
|
||||
function applyCountryDownloadsThreshold(setSelectedValues: SetDropdownFilterValues) {
|
||||
const threshold = countryDownloadsThreshold.value
|
||||
if (threshold === null) {
|
||||
return
|
||||
return null
|
||||
}
|
||||
|
||||
const selectedValues = countryFilterOptions.value
|
||||
.filter((country) => {
|
||||
return (
|
||||
(countryDownloadsByCode.value.get(country.value.trim().toUpperCase()) ?? 0) >= threshold
|
||||
)
|
||||
return (countryDownloadsByCode.value.get(country.value.trim().toUpperCase()) ?? 0) > threshold
|
||||
})
|
||||
.map((country) => country.value)
|
||||
|
||||
setDownloadsThresholdSelectedValues('country', selectedValues, setSelectedValues)
|
||||
return setDownloadsThresholdSelectedValues('country', selectedValues, setSelectedValues)
|
||||
}
|
||||
|
||||
function applyProjectVersionDownloadsThreshold(setSelectedValues: SetDropdownFilterValues) {
|
||||
const threshold = projectVersionDownloadsThreshold.value
|
||||
if (threshold === null) {
|
||||
return
|
||||
return null
|
||||
}
|
||||
|
||||
const selectedValues = projectVersionFilterOptions.value
|
||||
.filter((version) => {
|
||||
return (projectVersionDownloadsById.value.get(version.value) ?? 0) >= threshold
|
||||
return (projectVersionDownloadsById.value.get(version.value) ?? 0) > threshold
|
||||
})
|
||||
.map((version) => version.value)
|
||||
|
||||
setDownloadsThresholdSelectedValues('version_id', selectedValues, setSelectedValues)
|
||||
return setDownloadsThresholdSelectedValues('version_id', selectedValues, setSelectedValues)
|
||||
}
|
||||
|
||||
function setCountryDownloadsThreshold(
|
||||
@@ -876,12 +880,18 @@ function setDownloadsThresholdSelectedValues(
|
||||
categoryKey: DownloadsThresholdFilterCategory,
|
||||
selectedValues: string[],
|
||||
setSelectedValues: SetDropdownFilterValues,
|
||||
) {
|
||||
): DownloadsThresholdSelection {
|
||||
const normalizedSelectedValues = normalizeSelectedFilterValues(categoryKey, selectedValues, [])
|
||||
downloadsThresholdSelections.value = {
|
||||
...downloadsThresholdSelections.value,
|
||||
[categoryKey]: normalizeSelectedFilterValues(categoryKey, selectedValues, []),
|
||||
[categoryKey]: normalizedSelectedValues,
|
||||
}
|
||||
setSelectedValues(selectedValues)
|
||||
|
||||
return {
|
||||
categoryKey,
|
||||
selectedValues: normalizedSelectedValues,
|
||||
}
|
||||
}
|
||||
|
||||
function clearDownloadsThreshold(categoryKey: DownloadsThresholdFilterCategory) {
|
||||
@@ -923,8 +933,13 @@ async function runDownloadsThresholdQuery(
|
||||
closeMenu: CloseDownloadsThresholdMenu,
|
||||
event?: KeyboardEvent,
|
||||
) {
|
||||
applyDownloadsThreshold(setSelectedValues)
|
||||
const selection = applyDownloadsThreshold(setSelectedValues)
|
||||
closeMenu(event)
|
||||
if (selection) {
|
||||
const nextFilters = cloneSelectedFilters(draftSelectedFilters.value)
|
||||
nextFilters[selection.categoryKey] = selection.selectedValues
|
||||
draftSelectedFilters.value = nextFilters
|
||||
}
|
||||
await scheduleSelectedFiltersCommit()
|
||||
await refreshAnalyticsQuery()
|
||||
}
|
||||
|
||||
@@ -753,7 +753,7 @@ function applyProjectDownloadsThreshold(threshold: number | null) {
|
||||
}
|
||||
|
||||
const projectIds = projects.value
|
||||
.filter((project) => (projectDownloadsById.value.get(project.id) ?? 0) >= threshold)
|
||||
.filter((project) => (projectDownloadsById.value.get(project.id) ?? 0) > threshold)
|
||||
.map((project) => project.id)
|
||||
|
||||
projectDownloadsThresholdProjectIds.value = projectIds
|
||||
|
||||
Reference in New Issue
Block a user