potentially gather installed mods

This commit is contained in:
SpikeHD
2022-07-24 00:24:10 -07:00
parent a25645ef77
commit 811f437238
4 changed files with 115 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
import React from 'react'
import { getMods, ModData } from '../../../utils/gamebanana'
import { getInstalledMods, getMods, ModData } from '../../../utils/gamebanana'
import { LoadingCircle } from './LoadingCircle'
import './ModList.css'
@@ -11,7 +11,13 @@ interface IProps {
}
interface IState {
modList: ModData[]
modList: ModData[] | null
installedList:
| {
path: string
info: unknown
}[]
| null
}
export class ModList extends React.Component<IProps, IState> {
@@ -20,11 +26,26 @@ export class ModList extends React.Component<IProps, IState> {
console.log('Getting')
this.state = {
modList: null,
installedList: null,
}
this.downloadMod = this.downloadMod.bind(this)
}
async componentDidMount() {
if (this.props.mode === 'installed') return
if (this.props.mode === 'installed') {
const installedMods = await getInstalledMods()
console.log(installedMods)
this.setState({
installedList: installedMods,
})
return
}
const mods = await getMods(this.props.mode)
@@ -40,11 +61,14 @@ export class ModList extends React.Component<IProps, IState> {
render() {
return (
<div className="ModList">
{this.state && this.state.modList ? (
{(this.state.modList && this.props.mode !== 'installed') ||
(this.state.installedList && this.props.mode === 'installed') ? (
<div className="ModListInner">
{this.state.modList.map((mod: ModData) => (
<ModTile mod={mod} key={mod.id} onClick={this.downloadMod} />
))}
{this.props.mode === 'installed'
? this.state.installedList?.map((mod) => <></>)
: this.state.modList?.map((mod: ModData) => (
<ModTile mod={mod} key={mod.id} onClick={this.downloadMod} />
))}
</div>
) : (
<LoadingCircle />