From 48c0a618c585567a10beb6c7566d128749e8f547 Mon Sep 17 00:00:00 2001 From: Jozen Date: Mon, 16 Dec 2019 16:09:36 +0800 Subject: [PATCH] Add ability to apply assets to non-steam games Fixes #60 --- src/js/Search.jsx | 56 +++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/src/js/Search.jsx b/src/js/Search.jsx index d9fe172..f80e076 100644 --- a/src/js/Search.jsx +++ b/src/js/Search.jsx @@ -31,7 +31,6 @@ class Search extends React.Component { componentDidMount() { const { game } = this.state; - const { location } = this.props; let type = 'steam'; if (game.platform) { @@ -45,6 +44,41 @@ class Search extends React.Component { id = game.appid; } + if (game.platform === 'other') { + type = 'game'; + this.SGDB.searchGame(game.name) + .then((gameResp) => { + id = gameResp[0].id; + this.queryApi(type, id); + }); + } else { + this.queryApi(type, id); + } + } + + onClick(item, itemIndex) { + const { game, items } = this.state; + const { location } = this.props; + + const clonedItems = [...items]; + clonedItems[itemIndex].downloading = true; + + this.setState({ + items: clonedItems, + }); + + Steam.addAsset(location.state.assetType, game.appid, item.url).then(() => { + clonedItems[itemIndex].downloading = false; + this.setState({ + items: clonedItems, + }); + this.setState({ toGame: }); + }); + } + + queryApi(type, id) { + const { location } = this.props; + switch (location.state.assetType) { case 'horizontalGrid': this.SGDB.getGrids({ type, id }).then((res) => { @@ -75,26 +109,6 @@ class Search extends React.Component { } } - onClick(item, itemIndex) { - const { game, items } = this.state; - const { location } = this.props; - - const clonedItems = [...items]; - clonedItems[itemIndex].downloading = true; - - this.setState({ - items: clonedItems, - }); - - Steam.addAsset(location.state.assetType, game.appid, item.url).then(() => { - clonedItems[itemIndex].downloading = false; - this.setState({ - items: clonedItems, - }); - this.setState({ toGame: }); - }); - } - render() { const { isLoaded, toGame, items } = this.state; const { theme } = this.context;