diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 6d77c48ded..63182b7042 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -222,6 +222,10 @@ }, "title": "Downloads" }, + "emptyLibrary": { + "noGames": "Your library is empty. You can <1>log in using a store or click <3> to add one manually.", + "noResults": "The current filters produced no results." + }, "epic": { "offline-notification-body": "Online services may not work fully as Epic Games servers are offline!", "offline-notification-title": "offline" diff --git a/src/frontend/screens/Library/LibraryContext.tsx b/src/frontend/screens/Library/LibraryContext.tsx index d1d5d88c5d..8d655eb885 100644 --- a/src/frontend/screens/Library/LibraryContext.tsx +++ b/src/frontend/screens/Library/LibraryContext.tsx @@ -24,7 +24,8 @@ const initialContext: LibraryContextType = { sortInstalled: true, setSortInstalled: () => null, showSupportOfflineOnly: false, - setShowSupportOfflineOnly: () => null + setShowSupportOfflineOnly: () => null, + handleAddGameButtonClick: () => null } export default React.createContext(initialContext) diff --git a/src/frontend/screens/Library/components/AddGameButton/index.tsx b/src/frontend/screens/Library/components/AddGameButton/index.tsx new file mode 100644 index 0000000000..624e94cf5e --- /dev/null +++ b/src/frontend/screens/Library/components/AddGameButton/index.tsx @@ -0,0 +1,16 @@ +import React, { useContext } from 'react' +import { useTranslation } from 'react-i18next' +import LibraryContext from '../../LibraryContext' + +function AddGameButton() { + const { t } = useTranslation() + const { handleAddGameButtonClick } = useContext(LibraryContext) + + return ( + + ) +} + +export default AddGameButton diff --git a/src/frontend/screens/Library/components/EmptyLibrary/index.css b/src/frontend/screens/Library/components/EmptyLibrary/index.css new file mode 100644 index 0000000000..668e04c7b1 --- /dev/null +++ b/src/frontend/screens/Library/components/EmptyLibrary/index.css @@ -0,0 +1,14 @@ +.noResultsMessage { + font-size: 2rem; + max-width: 500px; + margin: auto; + padding-bottom: 20%; + .sideloadGameButton { + margin: 0; + display: inline; + vertical-align: text-bottom; + } + & a { + text-decoration: underline; + } +} diff --git a/src/frontend/screens/Library/components/EmptyLibrary/index.tsx b/src/frontend/screens/Library/components/EmptyLibrary/index.tsx new file mode 100644 index 0000000000..d8b70d109c --- /dev/null +++ b/src/frontend/screens/Library/components/EmptyLibrary/index.tsx @@ -0,0 +1,36 @@ +import React, { useContext } from 'react' +import ContextProvider from 'frontend/state/ContextProvider' +import { Trans, useTranslation } from 'react-i18next' +import './index.css' +import { NavLink } from 'react-router-dom' +import AddGameButton from '../AddGameButton' + +function EmptyLibraryMessage() { + const { epic, gog, amazon, sideloadedLibrary } = useContext(ContextProvider) + const { i18n } = useTranslation() + + let message = ( + + Your library is empty. You can log in using + a store or click to add one manually. + + ) + + if ( + epic.library.length + + gog.library.length + + amazon.library.length + + sideloadedLibrary.length > + 0 + ) { + message = ( + + The current filters produced no results. + + ) + } + + return

{message}

+} + +export default EmptyLibraryMessage diff --git a/src/frontend/screens/Library/components/LibraryHeader/index.tsx b/src/frontend/screens/Library/components/LibraryHeader/index.tsx index c3616d3f80..ae3cff9707 100644 --- a/src/frontend/screens/Library/components/LibraryHeader/index.tsx +++ b/src/frontend/screens/Library/components/LibraryHeader/index.tsx @@ -4,16 +4,13 @@ import ActionIcons from 'frontend/components/UI/ActionIcons' import { GameInfo } from 'common/types' import LibraryContext from '../../LibraryContext' import './index.css' +import AddGameButton from '../AddGameButton' type Props = { list: GameInfo[] - handleAddGameButtonClick: () => void } -export default React.memo(function LibraryHeader({ - list, - handleAddGameButtonClick -}: Props) { +export default React.memo(function LibraryHeader({ list }: Props) { const { t } = useTranslation() const { showFavourites } = useContext(LibraryContext) @@ -38,12 +35,7 @@ export default React.memo(function LibraryHeader({ ? t('favourites', 'Favourites') : t('title.allGames', 'All Games')} {numberOfGames} - + diff --git a/src/frontend/screens/Library/index.tsx b/src/frontend/screens/Library/index.tsx index 5d48c6f757..c17af56708 100644 --- a/src/frontend/screens/Library/index.tsx +++ b/src/frontend/screens/Library/index.tsx @@ -31,6 +31,7 @@ import { InstallModal } from './components' import LibraryContext from './LibraryContext' import { Category, PlatformsFilters, StoresFilters } from 'frontend/types' import { hasHelp } from 'frontend/hooks/hasHelp' +import EmptyLibraryMessage from './components/EmptyLibrary' const storage = window.localStorage @@ -594,7 +595,8 @@ export default React.memo(function Library(): JSX.Element { showSupportOfflineOnly, setShowSupportOfflineOnly: handleShowSupportOfflineOnly, sortDescending, - sortInstalled + sortInstalled, + handleAddGameButtonClick: () => handleModal('', 'sideload', null) }} >
@@ -621,20 +623,20 @@ export default React.memo(function Library(): JSX.Element { )} - handleModal('', 'sideload', null)} - /> + {refreshing && !refreshingInTheBackground && } - {(!refreshing || refreshingInTheBackground) && ( - - )} + {libraryToShow.length === 0 && } + + {libraryToShow.length > 0 && + (!refreshing || refreshingInTheBackground) && ( + + )}