-
Notifications
You must be signed in to change notification settings - Fork 885
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5fc7e0
commit b60a944
Showing
34 changed files
with
1,766 additions
and
1,947 deletions.
There are no files selected for viewing
191 changes: 0 additions & 191 deletions
191
newIDE/app/src/AssetStore/ExampleStore/ExampleDialog.js
This file was deleted.
Oops, something went wrong.
134 changes: 134 additions & 0 deletions
134
newIDE/app/src/AssetStore/ExampleStore/ExampleInformationPage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// @flow | ||
import { Trans } from '@lingui/macro'; | ||
import * as React from 'react'; | ||
import { | ||
type ExampleShortHeader, | ||
type Example, | ||
getExample, | ||
} from '../../Utils/GDevelopServices/Example'; | ||
import { isCompatibleWithAsset } from '../../Utils/GDevelopServices/Asset'; | ||
import PlaceholderError from '../../UI/PlaceholderError'; | ||
import { MarkdownText } from '../../UI/MarkdownText'; | ||
import Text from '../../UI/Text'; | ||
import AlertMessage from '../../UI/AlertMessage'; | ||
import { getIDEVersion } from '../../Version'; | ||
import { Column, Line } from '../../UI/Grid'; | ||
import Divider from '@material-ui/core/Divider'; | ||
import { ColumnStackLayout, ResponsiveLineStackLayout } from '../../UI/Layout'; | ||
import { ExampleThumbnailOrIcon } from './ExampleThumbnailOrIcon'; | ||
import Window from '../../Utils/Window'; | ||
import { UserPublicProfileChip } from '../../UI/User/UserPublicProfileChip'; | ||
import { ExampleDifficultyChip } from '../../UI/ExampleDifficultyChip'; | ||
import { ExampleSizeChip } from '../../UI/ExampleSizeChip'; | ||
const isDev = Window.isDev(); | ||
|
||
type Props = {| | ||
exampleShortHeader: ExampleShortHeader, | ||
|}; | ||
|
||
export const openExampleInWebApp = (example: Example) => { | ||
Window.openExternalURL( | ||
`${ | ||
isDev ? 'http://localhost:3000' : 'https://editor.gdevelop.io' | ||
}/?create-from-example=${example.slug}` | ||
); | ||
}; | ||
|
||
const ExampleInformationPage = ({ exampleShortHeader }: Props) => { | ||
const [error, setError] = React.useState<?Error>(null); | ||
const [example, setExample] = React.useState<?Example>(null); | ||
|
||
const loadExample = React.useCallback( | ||
async () => { | ||
setError(null); | ||
try { | ||
const example = await getExample(exampleShortHeader); | ||
setExample(example); | ||
} catch (error) { | ||
setError(error); | ||
} | ||
}, | ||
[exampleShortHeader] | ||
); | ||
|
||
React.useEffect( | ||
() => { | ||
loadExample(); | ||
}, | ||
[loadExample] | ||
); | ||
|
||
const isCompatible = isCompatibleWithAsset( | ||
getIDEVersion(), | ||
exampleShortHeader | ||
); | ||
const hasIcon = exampleShortHeader.previewImageUrls.length > 0; | ||
|
||
return ( | ||
<ColumnStackLayout expand noMargin> | ||
{!isCompatible && ( | ||
<AlertMessage kind="error"> | ||
<Trans> | ||
Unfortunately, this example requires a newer version of GDevelop to | ||
work. Update GDevelop to be able to open this example. | ||
</Trans> | ||
</AlertMessage> | ||
)} | ||
<ResponsiveLineStackLayout | ||
alignItems="center" | ||
noMargin | ||
noResponsiveLandscape | ||
> | ||
{hasIcon ? ( | ||
<ExampleThumbnailOrIcon exampleShortHeader={exampleShortHeader} /> | ||
) : null} | ||
<Column expand> | ||
{ | ||
<Line> | ||
<div style={{ flexWrap: 'wrap' }}> | ||
{exampleShortHeader.difficultyLevel && ( | ||
<ExampleDifficultyChip | ||
difficultyLevel={exampleShortHeader.difficultyLevel} | ||
/> | ||
)} | ||
{exampleShortHeader.codeSizeLevel && ( | ||
<ExampleSizeChip | ||
codeSizeLevel={exampleShortHeader.codeSizeLevel} | ||
/> | ||
)} | ||
{exampleShortHeader.authors && | ||
exampleShortHeader.authors.map(author => ( | ||
<UserPublicProfileChip | ||
user={author} | ||
key={author.id} | ||
isClickable | ||
/> | ||
))} | ||
</div> | ||
</Line> | ||
} | ||
<Text noMargin>{exampleShortHeader.shortDescription}</Text> | ||
</Column> | ||
</ResponsiveLineStackLayout> | ||
|
||
{example && example.description && ( | ||
<Column noMargin> | ||
<Divider /> | ||
<Text size="body" displayInlineAsSpan> | ||
<MarkdownText source={example.description} /> | ||
</Text> | ||
</Column> | ||
)} | ||
{!example && error && ( | ||
<PlaceholderError onRetry={loadExample}> | ||
<Trans> | ||
Can't load the example. Verify your internet connection or try again | ||
later. | ||
</Trans> | ||
</PlaceholderError> | ||
)} | ||
</ColumnStackLayout> | ||
); | ||
}; | ||
|
||
export default ExampleInformationPage; |
Oops, something went wrong.