Skip to content

Commit

Permalink
fix: Non-browse game container should work
Browse files Browse the repository at this point in the history
  • Loading branch information
colin969 committed Oct 19, 2023
1 parent a5973e9 commit fd3b97e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
13 changes: 13 additions & 0 deletions src/renderer/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import * as path from 'path';
import { GameOrderChangeEvent } from './components/GameOrder';
import { Paths } from './Paths';
import { ViewQuery } from './store/main/types';
import { GameDragEventData } from './components/pages/BrowsePage';
import { GameGridItem } from './components/GameGridItem';
import { GameListItem } from './components/GameListItem';

export const gameDragDataType = 'json/game-drag';

Expand Down Expand Up @@ -306,3 +309,13 @@ export function getBrowseSubPath(urlPath: string): string {
}
return '';
}

export function findGameDragEventDataGrid(element: EventTarget): GameDragEventData | undefined {
const game = findElementAncestor(element as Element, target => GameGridItem.isElement(target), true);
if (game) { return GameGridItem.getDragEventData(game); }
}

export function findGameDragEventDataList(element: EventTarget): GameDragEventData | undefined {
const game = findElementAncestor(element as Element, target => GameListItem.isElement(target), true);
if (game) { return GameListItem.getDragEventData(game); }
}
14 changes: 2 additions & 12 deletions src/renderer/components/RandomGames.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LangContext } from '@renderer/util/lang';
import { ViewGame } from '@shared/back/types';
import { LOGOS } from '@shared/constants';
import * as React from 'react';
import { findElementAncestor, getExtremeIconURL, getGameImageURL } from '../Util';
import { findGameDragEventDataGrid, getExtremeIconURL, getGameImageURL } from '../Util';
import { GameGridItem } from './GameGridItem';
import { GameItemContainer } from './GameItemContainer';
import { HomePageBox } from './HomePageBox';
Expand Down Expand Up @@ -70,7 +70,7 @@ export function RandomGames(props: RandomGamesProps) {
onGameContextMenu={onGameContextMenu}
onGameSelect={onGameSelect}
onGameLaunch={onLaunchGame}
findGameId={findGameId}>
findGameDragEventData={findGameDragEventDataGrid}>
{gameItems}
</GameItemContainer>
<SimpleButton
Expand All @@ -89,13 +89,3 @@ export function RandomGames(props: RandomGamesProps) {
</HomePageBox>
);
}

/**
* Try getting a game ID by checking an element and all of its ancestors.
*
* @param element Element or sub-element of a game.
*/
function findGameId(element: EventTarget): string | undefined {
const game = findElementAncestor(element as Element, target => GameGridItem.isElement(target), true);
if (game) { return GameGridItem.getId(game); }
}
10 changes: 6 additions & 4 deletions src/renderer/components/pages/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import ReactMarkdown from 'react-markdown';
import { Link } from 'react-router-dom';
import remarkGfm from 'remark-gfm';
import { Paths } from '../../Paths';
import { getExtremeIconURL, getGameImageURL, getPlatformIconURL, joinLibraryRoute } from '../../Util';
import { findGameDragEventDataGrid, getExtremeIconURL, getGameImageURL, getPlatformIconURL, joinLibraryRoute } from '../../Util';
import { WithPreferencesProps } from '../../containers/withPreferences';
import { WithSearchProps } from '../../containers/withSearch';
import { LangContext } from '../../util/lang';
Expand Down Expand Up @@ -276,8 +276,10 @@ export function HomePage(props: HomePageProps) {
if (selectedGotd) {
window.Shared.back.request(BackIn.GET_GAME, selectedGotd.id)
.then((fetchedInfo) => {
const game = fetchedInfo.game;
setLoadedGotd(game);
if (fetchedInfo) {
const game = fetchedInfo.game;
setLoadedGotd(game);
}
});
}
}, [selectedGotd]);
Expand All @@ -301,7 +303,7 @@ export function HomePage(props: HomePageProps) {
onGameContextMenu={(event, gameId) => props.onGameContextMenu(gameId)}
onGameSelect={(event, gameId) => props.onGameSelect(gameId)}
onGameLaunch={(event, gameId) => props.onLaunchGame(gameId)}
findGameId={() => loadedGotd.id}>
findGameDragEventData={findGameDragEventDataGrid}>
<GameGridItem
key={loadedGotd.id}
id={loadedGotd.id}
Expand Down

0 comments on commit fd3b97e

Please sign in to comment.