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

[UX] Add messages when there are no games to display in the library #3536

Merged
merged 1 commit into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@
},
"title": "Downloads"
},
"emptyLibrary": {
"noGames": "Your library is empty. You can <1>log in</1> using a store or click <3></3> to add one manually.",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these <1> and <3> are intentional, the Trans component replaces them with the tags from the children

"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"
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/screens/Library/LibraryContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const initialContext: LibraryContextType = {
sortInstalled: true,
setSortInstalled: () => null,
showSupportOfflineOnly: false,
setShowSupportOfflineOnly: () => null
setShowSupportOfflineOnly: () => null,
handleAddGameButtonClick: () => null
}

export default React.createContext(initialContext)
16 changes: 16 additions & 0 deletions src/frontend/screens/Library/components/AddGameButton/index.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<button className="sideloadGameButton" onClick={handleAddGameButtonClick}>
{t('add_game', 'Add Game')}
</button>
)
}

export default AddGameButton
14 changes: 14 additions & 0 deletions src/frontend/screens/Library/components/EmptyLibrary/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.noResultsMessage {
font-size: 2rem;
max-width: 500px;
margin: auto;
padding-bottom: 20%;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this message looks odd vertically centered, this padding moves it a bit up

.sideloadGameButton {
margin: 0;
display: inline;
vertical-align: text-bottom;
}
& a {
text-decoration: underline;
}
}
36 changes: 36 additions & 0 deletions src/frontend/screens/Library/components/EmptyLibrary/index.tsx
Original file line number Diff line number Diff line change
@@ -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 = (
<Trans i18n={i18n} i18nKey="emptyLibrary.noGames">
Your library is empty. You can <NavLink to="/login">log in</NavLink> using
a store or click <AddGameButton /> to add one manually.
</Trans>
)

if (
epic.library.length +
gog.library.length +
amazon.library.length +
sideloadedLibrary.length >
0
) {
message = (
<Trans i18n={i18n} i18nKey="emptyLibrary.noResults">
The current filters produced no results.
</Trans>
)
}

return <p className="noResultsMessage">{message}</p>
}

export default EmptyLibraryMessage
14 changes: 3 additions & 11 deletions src/frontend/screens/Library/components/LibraryHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -38,12 +35,7 @@ export default React.memo(function LibraryHeader({
? t('favourites', 'Favourites')
: t('title.allGames', 'All Games')}
<span className="numberOfgames">{numberOfGames}</span>
<button
className="sideloadGameButton"
onClick={handleAddGameButtonClick}
>
{t('add_game', 'Add Game')}
</button>
<AddGameButton />
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extracted this into a component to use it in the empty library message

</span>
<ActionIcons />
</div>
Expand Down
26 changes: 14 additions & 12 deletions src/frontend/screens/Library/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -594,7 +595,8 @@ export default React.memo(function Library(): JSX.Element {
showSupportOfflineOnly,
setShowSupportOfflineOnly: handleShowSupportOfflineOnly,
sortDescending,
sortInstalled
sortInstalled,
handleAddGameButtonClick: () => handleModal('', 'sideload', null)
}}
>
<Header />
Expand All @@ -621,20 +623,20 @@ export default React.memo(function Library(): JSX.Element {
</>
)}

<LibraryHeader
list={libraryToShow}
handleAddGameButtonClick={() => handleModal('', 'sideload', null)}
/>
<LibraryHeader list={libraryToShow} />

{refreshing && !refreshingInTheBackground && <UpdateComponent inline />}

{(!refreshing || refreshingInTheBackground) && (
<GamesList
library={libraryToShow}
layout={layout}
handleGameCardClick={handleModal}
/>
)}
{libraryToShow.length === 0 && <EmptyLibraryMessage />}

{libraryToShow.length > 0 &&
(!refreshing || refreshingInTheBackground) && (
<GamesList
library={libraryToShow}
layout={layout}
handleGameCardClick={handleModal}
/>
)}
</div>

<button id="backToTopBtn" onClick={backToTop} ref={backToTopElement}>
Expand Down
1 change: 1 addition & 0 deletions src/frontend/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export interface LibraryContextType {
setSortInstalled: (value: boolean) => void
showSupportOfflineOnly: boolean
setShowSupportOfflineOnly: (value: boolean) => void
handleAddGameButtonClick: () => void
}

export interface GameContextType {
Expand Down
Loading