Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify Build & Manage tabs #7217

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
78 changes: 55 additions & 23 deletions newIDE/app/src/AssetStore/ExampleStore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import GridList from '@material-ui/core/GridList';
import { getExampleAndTemplateTiles } from '../../MainFrame/EditorContainers/HomePage/CreateSection/utils';
import BackgroundText from '../../UI/BackgroundText';
import { ColumnStackLayout } from '../../UI/Layout';
import { isStartingPointExampleShortHeader } from '../../ProjectCreation/EmptyAndStartingPointProjects';

const styles = {
grid: {
Expand All @@ -39,27 +40,43 @@ const gameFilter = (
return true;
};

const noStartingPointFilter = (
item: PrivateGameTemplateListingData | ExampleShortHeader
) => {
if (item.previewImageUrls) {
// It's an example, filter out the starting points.
return !isStartingPointExampleShortHeader(item);
}

// It's a game template, always show.
return true;
};

type Props = {|
onSelectExampleShortHeader: ExampleShortHeader => void,
onSelectPrivateGameTemplateListingData: PrivateGameTemplateListingData => void,
i18n: I18nType,
onlyShowGames?: boolean,
hideStartingPoints?: boolean,
columnsCount: number,
rowToInsert?: {|
row: number,
element: React.Node,
|},
hideSearch?: boolean,
|};

const ExampleStore = ({
onSelectExampleShortHeader,
onSelectPrivateGameTemplateListingData,
i18n,
onlyShowGames,
hideStartingPoints,
columnsCount,
rowToInsert,
hideSearch,
}: Props) => {
const { receivedGameTemplates } = React.useContext(AuthenticatedUserContext);
const authenticatedUser = React.useContext(AuthenticatedUserContext);
const {
exampleShortHeadersSearchResults,
fetchExamplesAndFilters,
Expand Down Expand Up @@ -123,14 +140,19 @@ const ExampleStore = ({
const resultTiles: React.Node[] = React.useMemo(
() => {
return getExampleAndTemplateTiles({
receivedGameTemplates,
receivedGameTemplates: authenticatedUser.receivedGameTemplates,
privateGameTemplateListingDatas: privateGameTemplateListingDatasSearchResults
? privateGameTemplateListingDatasSearchResults
.map(({ item }) => item)
.filter(
privateGameTemplateListingData =>
!onlyShowGames || gameFilter(privateGameTemplateListingData)
)
.filter(
privateGameTemplateListingData =>
!hideStartingPoints ||
noStartingPointFilter(privateGameTemplateListingData)
)
: [],
exampleShortHeaders: exampleShortHeadersSearchResults
? exampleShortHeadersSearchResults
Expand All @@ -139,6 +161,11 @@ const ExampleStore = ({
exampleShortHeader =>
!onlyShowGames || gameFilter(exampleShortHeader)
)
.filter(
exampleShortHeader =>
!hideStartingPoints ||
noStartingPointFilter(exampleShortHeader)
)
: [],
onSelectPrivateGameTemplateListingData: privateGameTemplateListingData => {
sendGameTemplateInformationOpened({
Expand All @@ -160,13 +187,14 @@ const ExampleStore = ({
}).allGridItems;
},
[
receivedGameTemplates,
authenticatedUser,
privateGameTemplateListingDatasSearchResults,
exampleShortHeadersSearchResults,
onSelectPrivateGameTemplateListingData,
onSelectExampleShortHeader,
i18n,
onlyShowGames,
hideStartingPoints,
]
);

Expand All @@ -183,15 +211,17 @@ const ExampleStore = ({
numberOfTilesToDisplayUntilRowToInsert
);
return [
<GridList
cols={columnsCount}
style={styles.grid}
cellHeight="auto"
spacing={2}
key="first-tiles"
>
{firstTiles}
</GridList>,
firstTiles.length > 0 ? (
<GridList
cols={columnsCount}
style={styles.grid}
cellHeight="auto"
spacing={2}
key="first-tiles"
>
{firstTiles}
</GridList>
) : null,
rowToInsert ? (
<Line key="inserted-row">{rowToInsert.element}</Line>
) : null,
Expand All @@ -214,17 +244,19 @@ const ExampleStore = ({
return (
<React.Fragment>
<Column expand noMargin>
<Line>
<Column expand noMargin>
<SearchBar
value={localSearchText}
onChange={setSearchText}
onRequestSearch={() => {}}
ref={searchBarRef}
placeholder={t`Search examples`}
/>
</Column>
</Line>
{!hideSearch && (
<Line>
<Column expand noMargin>
<SearchBar
value={localSearchText}
onChange={setSearchText}
onRequestSearch={() => {}}
ref={searchBarRef}
placeholder={t`Search examples`}
/>
</Column>
</Line>
)}
{resultTiles.length === 0 ? (
<Column noMargin expand justifyContent="center">
<Spacer />
Expand Down
Loading
Loading