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

[UI/UX] Filters dropdown in Library. Show only installed #3266

Merged
merged 6 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Favorites filter composable. Refresh libraries in background
  • Loading branch information
arielj committed Nov 25, 2023
commit ef463b502367621c65fff1d89da72f5284fc4e86
15 changes: 3 additions & 12 deletions src/frontend/components/UI/ActionIcons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,18 @@ import {
faArrowDownZA,
faHardDrive as hardDriveSolid
} from '@fortawesome/free-solid-svg-icons'
import {
faHardDrive as hardDriveLight
} from '@fortawesome/free-regular-svg-icons'
import { faHardDrive as hardDriveLight } from '@fortawesome/free-regular-svg-icons'

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import React, { useContext } from 'react'
import { useTranslation } from 'react-i18next'
import ContextProvider from 'frontend/state/ContextProvider'
import FormControl from '../FormControl'
import './index.css'
import { Runner } from 'common/types'
import classNames from 'classnames'
import LibraryContext from 'frontend/screens/Library/LibraryContext'

interface Props {
library: Runner | 'all'
}

export default React.memo(function ActionIcons({ library }: Props) {
export default React.memo(function ActionIcons() {
const { t } = useTranslation()
const { refreshLibrary, refreshing } = useContext(ContextProvider)

Expand Down Expand Up @@ -94,9 +87,7 @@ export default React.memo(function ActionIcons({ library }: Props) {
title={t('generic.library.refresh', 'Refresh Library')}
onClick={async () =>
refreshLibrary({
checkForUpdates: true,
runInBackground: library === 'gog',
library
checkForUpdates: true
})
}
>
Expand Down
30 changes: 4 additions & 26 deletions src/frontend/screens/Library/components/LibraryHeader/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React, { useContext, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import ActionIcons from 'frontend/components/UI/ActionIcons'
import { amazonCategories, epicCategories } from 'frontend/helpers/library'
import { GameInfo } from 'common/types'
import { getLibraryTitle } from '../../constants'
import LibraryContext from '../../LibraryContext'
import './index.css'

Expand All @@ -17,7 +15,7 @@ export default React.memo(function LibraryHeader({
handleAddGameButtonClick
}: Props) {
const { t } = useTranslation()
const { category, showFavourites } = useContext(LibraryContext)
const { showFavourites } = useContext(LibraryContext)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we don't have a single category anymore (I didn't like the word category anyway haha), so the code that depended on this was removed


const numberOfGames = useMemo(() => {
if (!list) {
Expand All @@ -30,35 +28,15 @@ export default React.memo(function LibraryHeader({

const total = list.length - dlcCount
return total > 0 ? `${total}` : 0
}, [list, category])

function getLibrary() {
if (category === 'all') {
return category
}

if (epicCategories.includes(category)) {
return 'legendary'
}

if (amazonCategories.includes(category)) {
return 'nile'
}

if (category === 'sideload') {
return 'sideload'
}

return 'gog'
}
}, [list])

return (
<h5 className="libraryHeader">
<div className="libraryHeaderWrapper">
<span className="libraryTitle">
{showFavourites
? t('favourites', 'Favourites')
: `${getLibraryTitle(category, t)}`}
: t('title.allGames', 'All Games')}
<span className="numberOfgames">{numberOfGames}</span>
<button
className="sideloadGameButton"
Expand All @@ -67,7 +45,7 @@ export default React.memo(function LibraryHeader({
{t('add_game', 'Add Game')}
</button>
</span>
<ActionIcons library={getLibrary()} />
<ActionIcons />
</div>
</h5>
)
Expand Down
20 changes: 0 additions & 20 deletions src/frontend/screens/Library/constants.ts
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we can't change the library title based on the category cause now they are composable, so removing this

This file was deleted.

66 changes: 35 additions & 31 deletions src/frontend/screens/Library/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,11 @@ export default React.memo(function Library(): JSX.Element {
})
}
return tempArray
}, [showFavourites, showFavouritesLibrary, favouriteGames, epic, gog])
}, [showFavourites, showFavouritesLibrary, favouriteGames, epic, gog, amazon])

const favouritesIds = useMemo(() => {
return favourites.map((game) => `${game.app_name}_${game.runner}`)
}, [favourites])

// select library
const libraryToShow = useMemo(() => {
Expand All @@ -331,39 +335,39 @@ export default React.memo(function Library(): JSX.Element {
displayedStores = Object.keys(storesFilters)
}

const showEpic = epic.username && displayedStores.includes('legendary')
const showGog = gog.username && displayedStores.includes('gog')
const showAmazon = amazon.user_id && displayedStores.includes('nile')
const showSideloaded = displayedStores.includes('sideload')

const epicLibrary = showEpic ? epic.library : []
const gogLibrary = showGog ? gog.library : []
const sideloadedApps = showSideloaded ? sideloadedLibrary : []
const amazonLibrary = showAmazon ? amazon.library : []

library = [
...sideloadedApps,
...epicLibrary,
...gogLibrary,
...amazonLibrary
]

if (showFavouritesLibrary) {
library = favourites.filter((game) =>
displayedStores.includes(game?.runner)
library = library.filter((game) =>
favouritesIds.includes(`${game.app_name}_${game.runner}`)
)
} else {
const showEpic = epic.username && displayedStores.includes('legendary')
const showGog = gog.username && displayedStores.includes('gog')
const showAmazon = amazon.user_id && displayedStores.includes('nile')
const showSideloaded = displayedStores.includes('sideload')

const epicLibrary = showEpic ? epic.library : []
const gogLibrary = showGog ? gog.library : []
const sideloadedApps = showSideloaded ? sideloadedLibrary : []
const amazonLibrary = showAmazon ? amazon.library : []

library = [
...sideloadedApps,
...epicLibrary,
...gogLibrary,
...amazonLibrary
]

if (showInstalledOnly) {
library = library.filter((game) => game.is_installed)
}
}

if (!showNonAvailable) {
const nonAvailbleGames = storage.getItem('nonAvailableGames') || '[]'
const nonAvailbleGamesArray = JSON.parse(nonAvailbleGames)
library = library.filter(
(game) => !nonAvailbleGamesArray.includes(game.app_name)
)
}
if (showInstalledOnly) {
library = library.filter((game) => game.is_installed)
}

if (!showNonAvailable) {
const nonAvailbleGames = storage.getItem('nonAvailableGames') || '[]'
const nonAvailbleGamesArray = JSON.parse(nonAvailbleGames)
library = library.filter(
(game) => !nonAvailbleGamesArray.includes(game.app_name)
)
}

// filter
Expand Down