Skip to content

Commit

Permalink
Fix games sometimes disappearing from the dashboard (#7366)
Browse files Browse the repository at this point in the history
* This was caused by games wrongly being considered as not saved during the export, and they were hidden from the dashboard afterwards
  • Loading branch information
ClementPasteau authored Feb 4, 2025
1 parent 3d0b264 commit 601a4e2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
4 changes: 3 additions & 1 deletion newIDE/app/src/GameDashboard/GamesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,12 @@ const GamesList = ({

return allItems.filter(
item =>
// Filter out draft games which are not the current opened project.
// Filter out draft games which don't have a project file linked to it (local or cloud)
// and which are not the current opened project.
!(
item.game &&
item.game.savedStatus === 'draft' &&
(!item.projectFiles || !item.projectFiles.length) &&
(!project || item.game.id !== project.getProjectUuid())
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const ProjectFileList = ({
onDeleteCloudProject,
disabled,
}: Props) => {
const projectFiles = useProjectsListFor(game);
const projectFiles = useProjectsListFor(game.id);
const contextMenu = React.useRef<?ContextMenuInterface>(null);
const [loadingProjectId, setLoadingProjectId] = React.useState<?string>(null);
const { removeRecentProjectFile } = React.useContext(PreferencesContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { type PrivateGameTemplateListingData } from '../../../../Utils/GDevelopS
import { type ExampleShortHeader } from '../../../../Utils/GDevelopServices/Example';
import { type PrivateGameTemplate } from '../../../../Utils/GDevelopServices/Asset';
import { type CarouselThumbnail } from '../../../../UI/Carousel';
import { type Game } from '../../../../Utils/GDevelopServices/Game';
import {
ExampleTile,
PrivateGameTemplateTile,
Expand Down Expand Up @@ -101,21 +100,22 @@ export const getStorageProviderByInternalName = (
);
};

export const useProjectsListFor = (game: ?Game) => {
export const useProjectsListFor = (gameId: string | null) => {
const { getRecentProjectFiles } = React.useContext(PreferencesContext);
const authenticatedUser = React.useContext(AuthenticatedUserContext);

const { cloudProjects } = authenticatedUser;

let projectFiles: Array<FileMetadataAndStorageProviderName> = getRecentProjectFiles().filter(
file => !game || (file.fileMetadata && file.fileMetadata.gameId === game.id)
file =>
!gameId || (file.fileMetadata && file.fileMetadata.gameId === gameId)
);

if (cloudProjects) {
projectFiles = projectFiles.concat(
transformCloudProjectsIntoFileMetadataWithStorageProviderName(
cloudProjects.filter(
cloudProject => !game || cloudProject.gameId === game.id
cloudProject => !gameId || cloudProject.gameId === gameId
)
)
);
Expand Down
9 changes: 6 additions & 3 deletions newIDE/app/src/Utils/UseGameAndBuildsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
findLeaderboardsToReplaceInProject,
replaceLeaderboardsInProject,
} from '../Leaderboard/UseLeaderboardReplacer';
import { useProjectsListFor } from '../MainFrame/EditorContainers/HomePage/CreateSection/utils';

export const getDefaultRegisterGameProperties = ({
projectId,
Expand Down Expand Up @@ -69,6 +70,8 @@ export const useGameManager = ({
} = useMultiplayerLobbyConfigurator();

const [game, setGame] = React.useState<?Game>(null);
const projectId = project ? project.getProjectUuid() : null;
const projectFiles = useProjectsListFor(projectId);
const [
gameAvailabilityError,
setGameAvailabilityError,
Expand Down Expand Up @@ -154,6 +157,7 @@ export const useGameManager = ({
error
);
if (extractedStatusAndCode && extractedStatusAndCode.status === 404) {
const hasProjectFiles = projectFiles.length > 0;
// If the game is not registered, register it before launching the export.
await registerGame(
getAuthorizationHeader,
Expand All @@ -162,9 +166,7 @@ export const useGameManager = ({
projectId: gameId,
projectName: project.getName(),
projectAuthor: project.getAuthor(),
// Assume a project going through the export process is not saved yet.
// It will be marked as saved when the user saves it next anyway.
savedStatus: 'draft',
savedStatus: hasProjectFiles ? 'saved' : 'draft',
})
);

Expand Down Expand Up @@ -209,6 +211,7 @@ export const useGameManager = ({
configureMultiplayerLobbiesIfNeeded,
authenticatedUser,
onGameRegistered,
projectFiles,
]
);

Expand Down

0 comments on commit 601a4e2

Please sign in to comment.