Skip to content

Commit e45256c

Browse files
Fix a few issues with displaying projects correctly in the create section (#7349)
1 parent 1ee2d57 commit e45256c

File tree

5 files changed

+46
-40
lines changed

5 files changed

+46
-40
lines changed

newIDE/app/src/GameDashboard/GamesList.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,7 @@ const getDashboardItemsToDisplay = ({
146146
orderBy: GamesDashboardOrderBy,
147147
|}): ?Array<DashboardItem> => {
148148
if (!allDashboardItems) return null;
149-
let itemsToDisplay: DashboardItem[] = allDashboardItems.filter(
150-
item =>
151-
// First, filter out unsaved games, unless they are the opened project.
152-
!item.game ||
153-
item.game.savedStatus !== 'draft' ||
154-
(project && item.game.id === project.getProjectUuid())
155-
);
149+
let itemsToDisplay: DashboardItem[] = [...allDashboardItems];
156150

157151
if (searchText) {
158152
// If there is a search, just return those items, ordered by the search relevance.
@@ -165,14 +159,15 @@ const getDashboardItemsToDisplay = ({
165159
itemsToDisplay = searchResults.map(result => result.item);
166160
} else {
167161
// If there is no search, sort the items by the selected order.
168-
itemsToDisplay =
169-
orderBy === 'totalSessions'
170-
? itemsToDisplay.sort(totalSessionsSort)
171-
: orderBy === 'weeklySessions'
172-
? itemsToDisplay.sort(lastWeekSessionsSort)
173-
: orderBy === 'lastModifiedAt'
174-
? itemsToDisplay.sort(lastModifiedAtSort)
175-
: itemsToDisplay;
162+
if (orderBy) {
163+
itemsToDisplay.sort(
164+
orderBy === 'totalSessions'
165+
? totalSessionsSort
166+
: orderBy === 'weeklySessions'
167+
? lastWeekSessionsSort
168+
: lastModifiedAtSort
169+
);
170+
}
176171

177172
// If a project is opened, no search is done, and sorted by last modified date,
178173
// then the opened project should be displayed first.
@@ -325,9 +320,19 @@ const GamesList = ({
325320
file => !games.find(game => game.id === file.fileMetadata.gameId)
326321
)
327322
.map(file => ({ projectFiles: [file] }));
328-
return [...projectFilesWithGame, ...projectFilesWithoutGame];
323+
const allItems = [...projectFilesWithGame, ...projectFilesWithoutGame];
324+
325+
return allItems.filter(
326+
item =>
327+
// Filter out draft games which are not the current opened project.
328+
!(
329+
item.game &&
330+
item.game.savedStatus === 'draft' &&
331+
(!project || item.game.id !== project.getProjectUuid())
332+
)
333+
);
329334
},
330-
[games, allRecentProjectFiles]
335+
[games, allRecentProjectFiles, project]
331336
);
332337

333338
const totalNumberOfPages = allDashboardItems

newIDE/app/src/MainFrame/EditorContainers/HomePage/CreateSection/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ const CreateSection = ({
166166
authenticatedUser
167167
);
168168
const allRecentProjectFiles = useProjectsListFor(null);
169-
const hasAProjectOpenedOrSavedOrGameRegistered =
170-
!!project || (!!games && games.length) || !!allRecentProjectFiles.length;
169+
const savedGames = (games || []).filter(game => game.savedStatus !== 'draft');
170+
const hasAProjectOpenedNowOrRecentlyOrGameSaved =
171+
!!project || savedGames.length || !!allRecentProjectFiles.length;
171172
const hidePerformanceDashboard =
172173
!!limits &&
173174
!!limits.capabilities.classrooms &&
@@ -460,7 +461,7 @@ const CreateSection = ({
460461
<SectionRow expand>
461462
{!!profile || loginState === 'done' ? (
462463
<ColumnStackLayout noMargin>
463-
{hidePerformanceDashboard ? null : hasAProjectOpenedOrSavedOrGameRegistered ? (
464+
{hidePerformanceDashboard ? null : hasAProjectOpenedNowOrRecentlyOrGameSaved ? (
464465
<ColumnStackLayout noMargin>
465466
<Grid container spacing={2}>
466467
<UserEarningsWidget
@@ -559,7 +560,7 @@ const CreateSection = ({
559560
/>
560561
</ColumnStackLayout>
561562
)}
562-
{!hasAProjectOpenedOrSavedOrGameRegistered && (
563+
{!hasAProjectOpenedNowOrRecentlyOrGameSaved && (
563564
<ColumnStackLayout noMargin>
564565
<Line noMargin justifyContent="space-between">
565566
<Text size="block-title" noMargin>

newIDE/app/src/MainFrame/Preferences/PreferencesContext.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ export type Preferences = {|
274274
name: EditorMosaicName,
275275
node: ?EditorMosaicNode
276276
) => void,
277-
getRecentProjectFiles: () => Array<FileMetadataAndStorageProviderName>,
277+
getRecentProjectFiles: (
278+
options: ?{| limit: number |}
279+
) => Array<FileMetadataAndStorageProviderName>,
278280
insertRecentProjectFile: (
279281
fileMetadata: FileMetadataAndStorageProviderName
280282
) => void,
@@ -423,7 +425,7 @@ export const initialPreferences = {
423425
name: EditorMosaicName,
424426
node: ?EditorMosaicNode
425427
) => {},
426-
getRecentProjectFiles: () => [],
428+
getRecentProjectFiles: options => [],
427429
insertRecentProjectFile: () => {},
428430
removeRecentProjectFile: () => {},
429431
getAutoOpenMostRecentProject: () => true,

newIDE/app/src/MainFrame/Preferences/PreferencesProvider.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ type Props = {|
3939
type State = Preferences;
4040

4141
const localStorageItem = 'gd-preferences';
42-
const MAX_RECENT_FILES_COUNT = 20;
4342

4443
export const loadPreferencesFromLocalStorage = (): ?PreferencesValues => {
4544
try {
@@ -85,7 +84,7 @@ export const getInitialPreferences = () => {
8584
return { ...initialPreferences.values, language: languageOrLocale };
8685
};
8786

88-
const getPreferences = () => {
87+
const getPreferences = (): PreferencesValues => {
8988
const preferences =
9089
loadPreferencesFromLocalStorage() || getInitialPreferences();
9190
setLanguageInDOM(preferences.language);
@@ -718,8 +717,12 @@ export default class PreferencesProvider extends React.Component<Props, State> {
718717
);
719718
}
720719

721-
_getRecentProjectFiles() {
722-
return this.state.values.recentProjectFiles;
720+
_getRecentProjectFiles(
721+
options: ?{| limit: number |}
722+
): Array<FileMetadataAndStorageProviderName> {
723+
const limit = options ? options.limit : undefined;
724+
const recentProjectFiles = this.state.values.recentProjectFiles;
725+
return limit ? recentProjectFiles.slice(0, limit) : recentProjectFiles;
723726
}
724727

725728
_setRecentProjectFiles(recents: Array<FileMetadataAndStorageProviderName>) {
@@ -742,24 +745,19 @@ export default class PreferencesProvider extends React.Component<Props, State> {
742745
const isNotNewRecentFile = recentFile =>
743746
recentFile.fileMetadata.fileIdentifier !==
744747
newRecentFile.fileMetadata.fileIdentifier;
745-
this._setRecentProjectFiles(
746-
[newRecentFile, ...recentProjectFiles.filter(isNotNewRecentFile)].slice(
747-
0,
748-
MAX_RECENT_FILES_COUNT
749-
)
750-
);
748+
this._setRecentProjectFiles([
749+
newRecentFile,
750+
...recentProjectFiles.filter(isNotNewRecentFile),
751+
]);
751752
}
752753

753754
_removeRecentProjectFile(recentFile: FileMetadataAndStorageProviderName) {
754755
const isNotRemovedRecentFile = recentFileItem =>
755756
recentFileItem.fileMetadata.fileIdentifier !==
756757
recentFile.fileMetadata.fileIdentifier;
757-
this._setRecentProjectFiles(
758-
[...this._getRecentProjectFiles().filter(isNotRemovedRecentFile)].slice(
759-
0,
760-
MAX_RECENT_FILES_COUNT
761-
)
762-
);
758+
this._setRecentProjectFiles([
759+
...this._getRecentProjectFiles().filter(isNotRemovedRecentFile),
760+
]);
763761
}
764762

765763
_getAutoOpenMostRecentProject() {

newIDE/app/src/MainFrame/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3523,7 +3523,7 @@ const MainFrame = (props: Props) => {
35233523
i18n: i18n,
35243524
project: state.currentProject,
35253525
canSaveProjectAs,
3526-
recentProjectFiles: preferences.getRecentProjectFiles(),
3526+
recentProjectFiles: preferences.getRecentProjectFiles({ limit: 20 }),
35273527
shortcutMap,
35283528
isApplicationTopLevelMenu: false,
35293529
};

0 commit comments

Comments
 (0)