From 34fecdc2ebb7de0095049a24fad92a96dfbd0e49 Mon Sep 17 00:00:00 2001 From: AlexandreSi <32449369+AlexandreSi@users.noreply.github.com> Date: Tue, 7 May 2024 16:44:18 +0200 Subject: [PATCH] Handle example opening messages from gd.games public profile --- newIDE/app/src/Profile/PublicProfileDialog.js | 14 ++++++++++++-- newIDE/app/src/UI/GdGamesFrame.js | 2 ++ .../PublicProfileDialog.stories.js | 3 +++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/newIDE/app/src/Profile/PublicProfileDialog.js b/newIDE/app/src/Profile/PublicProfileDialog.js index 2714b56981e0..e865cb192035 100644 --- a/newIDE/app/src/Profile/PublicProfileDialog.js +++ b/newIDE/app/src/Profile/PublicProfileDialog.js @@ -9,6 +9,7 @@ import { type PrivateGameTemplateListingData, type PrivateAssetPackListingData, } from '../Utils/GDevelopServices/Shop'; +import { type ExampleShortHeader } from '../Utils/GDevelopServices/Example'; import { useStableUpToDateCallback } from '../Utils/UseStableUpToDateCallback'; type Props = {| @@ -18,8 +19,9 @@ type Props = {| privateAssetPackListingData: PrivateAssetPackListingData ) => void, onGameTemplateOpen?: ( - privateAssetPackListingData: PrivateGameTemplateListingData + privateGameTemplateListingData: PrivateGameTemplateListingData ) => void, + onExampleOpen?: (exampleShortHeader: ExampleShortHeader) => void, |}; const PublicProfileDialog = ({ @@ -27,6 +29,7 @@ const PublicProfileDialog = ({ onClose, onAssetPackOpen, onGameTemplateOpen, + onExampleOpen, }: Props) => { const callbacks = React.useMemo( () => ({ @@ -44,8 +47,15 @@ const PublicProfileDialog = ({ } } : null, + openExample: onExampleOpen + ? (data: GdGamesMessageEventData) => { + if (data.exampleShortHeader) { + onExampleOpen(data.exampleShortHeader); + } + } + : null, }), - [onAssetPackOpen, onGameTemplateOpen] + [onAssetPackOpen, onGameTemplateOpen, onExampleOpen] ); const onMessageReceived = React.useCallback( diff --git a/newIDE/app/src/UI/GdGamesFrame.js b/newIDE/app/src/UI/GdGamesFrame.js index 41ec54aa7bcd..b82f9c26c95c 100644 --- a/newIDE/app/src/UI/GdGamesFrame.js +++ b/newIDE/app/src/UI/GdGamesFrame.js @@ -10,11 +10,13 @@ import { type PrivateGameTemplateListingData, type PrivateAssetPackListingData, } from '../Utils/GDevelopServices/Shop'; +import { type ExampleShortHeader } from '../Utils/GDevelopServices/Example'; export type GdGamesMessageEventData = $ReadOnly<{ id?: string | any, privateAssetPackListingData?: PrivateAssetPackListingData, privateGameTemplateListingData?: PrivateGameTemplateListingData, + exampleShortHeader?: ExampleShortHeader, }>; type Props = {| diff --git a/newIDE/app/src/stories/componentStories/PublicProfileDialog.stories.js b/newIDE/app/src/stories/componentStories/PublicProfileDialog.stories.js index 9475be90ddd8..3fb4ba061512 100644 --- a/newIDE/app/src/stories/componentStories/PublicProfileDialog.stories.js +++ b/newIDE/app/src/stories/componentStories/PublicProfileDialog.stories.js @@ -16,6 +16,7 @@ export const WithGameTemplates = () => ( onClose={action('onClose')} onAssetPackOpen={action('onAssetPackOpen')} onGameTemplateOpen={action('onGameTemplateOpen')} + onExampleOpen={action('onExampleOpen')} /> ); @@ -25,6 +26,7 @@ export const WithAssetPacks = () => ( onClose={action('onClose')} onAssetPackOpen={action('onAssetPackOpen')} onGameTemplateOpen={action('onGameTemplateOpen')} + onExampleOpen={action('onExampleOpen')} /> ); @@ -34,5 +36,6 @@ export const WithGames = () => ( onClose={action('onClose')} onAssetPackOpen={action('onAssetPackOpen')} onGameTemplateOpen={action('onGameTemplateOpen')} + onExampleOpen={action('onExampleOpen')} /> );