mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-13 15:44:35 +01:00
Better mod searching
This commit is contained in:
@@ -13,7 +13,8 @@ pub async fn get_download_links(mod_id: String) -> String {
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn list_submissions(mode: String, page: String) -> String {
|
||||
pub async fn list_submissions(mode: String, page: String, search: String) -> String {
|
||||
if search.is_empty() {
|
||||
web::query(
|
||||
format!(
|
||||
"{}/apiv9/Util/Game/Submissions?_idGameRow=8552&_nPage={}&_nPerpage=50&_sMode={}",
|
||||
@@ -22,6 +23,16 @@ pub async fn list_submissions(mode: String, page: String) -> String {
|
||||
.as_str(),
|
||||
)
|
||||
.await
|
||||
} else {
|
||||
web::query(
|
||||
format!(
|
||||
"{}/apiv11/Util/Search/Results?_nPage={}&_sOrder=best_match&_idGameRow=8552&_sSearchString={}&_csvFields=name,description,article,attribs,studio,owner,credits",
|
||||
SITE_URL, page, search
|
||||
)
|
||||
.as_str()
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'react'
|
||||
import { getConfigOption } from '../../../utils/configuration'
|
||||
import { getAllMods, getInstalledMods, getMods, ModData, PartialModData } from '../../../utils/gamebanana'
|
||||
import { getInstalledMods, getMods, ModData, PartialModData } from '../../../utils/gamebanana'
|
||||
import { LoadingCircle } from './LoadingCircle'
|
||||
|
||||
import './ModList.css'
|
||||
@@ -64,16 +64,7 @@ export class ModList extends React.Component<IProps, IState> {
|
||||
return
|
||||
}
|
||||
|
||||
let mods: ModData[]
|
||||
|
||||
if (!(this.props.search == '')) {
|
||||
// idk the api so just filter all mods to search
|
||||
mods = (await getAllMods(this.props.mode)).filter((mod) =>
|
||||
mod.name.toLowerCase().includes(this.props.search.toLowerCase())
|
||||
)
|
||||
} else {
|
||||
mods = await getMods(this.props.mode, this.props.page)
|
||||
}
|
||||
const mods = await getMods(this.props.mode, this.props.page, this.props.search)
|
||||
|
||||
const horny = await getConfigOption('horny_mode')
|
||||
|
||||
|
||||
@@ -117,23 +117,10 @@ interface ModDownload {
|
||||
containsExe: boolean
|
||||
}
|
||||
|
||||
export async function getMods(mode: string, page: number) {
|
||||
export async function getMods(mode: string, page: number, search: string) {
|
||||
let modList: GamebananaResponse[] = []
|
||||
|
||||
const resp = JSON.parse(
|
||||
await invoke('list_submissions', {
|
||||
mode,
|
||||
page: '' + page,
|
||||
})
|
||||
)
|
||||
|
||||
modList = [...modList, ...resp]
|
||||
|
||||
return formatGamebananaData(modList)
|
||||
}
|
||||
|
||||
export async function getAllMods(mode: string) {
|
||||
let modList: GamebananaResponse[] = []
|
||||
if (search.length > 0) {
|
||||
let hadMods = true
|
||||
let page = 1
|
||||
|
||||
@@ -142,18 +129,34 @@ export async function getAllMods(mode: string) {
|
||||
await invoke('list_submissions', {
|
||||
mode,
|
||||
page: '' + page,
|
||||
search: search
|
||||
})
|
||||
)
|
||||
|
||||
if (resp.length === 0) hadMods = false
|
||||
const total = resp._aMetadata._nRecordCount
|
||||
|
||||
modList = [...modList, ...resp]
|
||||
if (page > (total / 15)) hadMods = false
|
||||
|
||||
modList = [...modList, ...resp._aRecords]
|
||||
page++
|
||||
}
|
||||
|
||||
return formatGamebananaData(modList)
|
||||
}
|
||||
|
||||
const resp = JSON.parse(
|
||||
await invoke('list_submissions', {
|
||||
mode,
|
||||
page: '' + page,
|
||||
search: '',
|
||||
})
|
||||
)
|
||||
|
||||
modList = [...modList, ...resp]
|
||||
|
||||
return formatGamebananaData(modList)
|
||||
}
|
||||
|
||||
export async function formatGamebananaData(obj: GamebananaResponse[]) {
|
||||
if (!obj) return []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user