forked from modrinth/knossos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04faa85
commit 6e3be0f
Showing
5 changed files
with
131 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
type query = string | null | ||
export function arrayFromQuery(x?: query | query[] | undefined): string[] { | ||
if (typeof x === 'string') { | ||
return [x] | ||
} else { | ||
return (x ?? []) as string[] | ||
} | ||
} | ||
|
||
export function intersection(A: any[], B: any[]): any[] { | ||
return A.filter((x) => B.includes(x)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Ref } from 'vue' | ||
|
||
interface Version { | ||
game_versions: any[] | ||
loaders: any[] | ||
version_type: any | ||
} | ||
|
||
export default (unfilteredVersions: Ref<Version[]> | Version[], onQueryChange: () => void) => { | ||
const route = useRoute() | ||
|
||
watch( | ||
() => `${route.query.g}, ${route.query.l}, ${route.query.c}`, | ||
(_) => onQueryChange() | ||
) | ||
|
||
return computed((): Version[] => { | ||
let filteredVersions = unref(unfilteredVersions) | ||
|
||
const selectedGameVersions = arrayFromQuery(route.query.g) | ||
if (selectedGameVersions.length > 0) { | ||
filteredVersions = filteredVersions.filter(v => intersection(selectedGameVersions, v.game_versions).length > 0) | ||
} | ||
|
||
const selectedLoaders = arrayFromQuery(route.query.l) | ||
if (selectedLoaders.length > 0) { | ||
filteredVersions = filteredVersions.filter((v) => intersection(selectedLoaders, v.loaders).length > 0) | ||
} | ||
|
||
const selectedVersionTypes = arrayFromQuery(route.query.c) | ||
if (selectedVersionTypes.length > 0) { | ||
filteredVersions = filteredVersions.filter((v) => selectedVersionTypes.includes(v.version_type)) | ||
} | ||
|
||
return filteredVersions | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters