Skip to content
This repository has been archived by the owner on Jun 6, 2022. It is now read-only.

Commit

Permalink
Add ability to apply assets to non-steam games
Browse files Browse the repository at this point in the history
Fixes #60
  • Loading branch information
doZennn committed Dec 16, 2019
1 parent ed29e29 commit 48c0a61
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions src/js/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class Search extends React.Component {

componentDidMount() {
const { game } = this.state;
const { location } = this.props;

let type = 'steam';
if (game.platform) {
Expand All @@ -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: <Redirect to={{ pathname: '/game', state: location.state }} /> });
});
}

queryApi(type, id) {
const { location } = this.props;

switch (location.state.assetType) {
case 'horizontalGrid':
this.SGDB.getGrids({ type, id }).then((res) => {
Expand Down Expand Up @@ -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: <Redirect to={{ pathname: '/game', state: location.state }} /> });
});
}

render() {
const { isLoaded, toGame, items } = this.state;
const { theme } = this.context;
Expand Down

0 comments on commit 48c0a61

Please sign in to comment.