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 offline support filter #3371

Merged
merged 2 commits into from
Jan 1, 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
1 change: 1 addition & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
"show_favourites_only": "Show Favourites only",
"show_hidden": "Show Hidden",
"show_installed_only": "Show Installed only",
"show_support_offline_only": "Show offline-supported only",
"uncategorized": "Uncategorized"
},
"help": {
Expand Down
18 changes: 17 additions & 1 deletion src/frontend/components/UI/LibraryFilters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export default function LibraryFilters() {
storesFilters,
setStoresFilters,
platformsFilters,
setPlatformsFilters
setPlatformsFilters,
showSupportOfflineOnly,
setShowSupportOfflineOnly
} = useContext(LibraryContext)

const toggleShowHidden = () => {
Expand All @@ -47,6 +49,10 @@ export default function LibraryFilters() {
setShowInstalledOnly(!showInstalledOnly)
}

const toggleOnlySupportOffline = () => {
setShowSupportOfflineOnly(!showSupportOfflineOnly)
}

const toggleStoreFilter = (store: Category) => {
const currentValue = storesFilters[store]
const newFilters = { ...storesFilters, [store]: !currentValue }
Expand Down Expand Up @@ -193,6 +199,16 @@ export default function LibraryFilters() {
value={showInstalledOnly}
title={t('header.show_installed_only', 'Show Installed only')}
/>
<ToggleSwitch
key="only-support-offline"
htmlId="only-support-offline"
handleChange={() => toggleOnlySupportOffline()}
value={showSupportOfflineOnly}
title={t(
'header.show_support_offline_only',
'Show offline-supported only'
)}
/>
<hr />
<button
type="reset"
Expand Down
4 changes: 3 additions & 1 deletion src/frontend/screens/Library/LibraryContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const initialContext: LibraryContextType = {
sortDescending: true,
setSortDescending: () => null,
sortInstalled: true,
setSortInstalled: () => null
setSortInstalled: () => null,
showSupportOfflineOnly: false,
setShowSupportOfflineOnly: () => null
}

export default React.createContext(initialContext)
17 changes: 16 additions & 1 deletion src/frontend/screens/Library/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ export default React.memo(function Library(): JSX.Element {
setShowNonAvailable(value)
}

const [showSupportOfflineOnly, setSupportOfflineOnly] = useState(
JSON.parse(storage.getItem('show_support_offline_only') || 'false')
)
const handleShowSupportOfflineOnly = (value: boolean) => {
storage.setItem('show_support_offline_only', JSON.stringify(value))
setSupportOfflineOnly(value)
}

const [showModal, setShowModal] = useState<ModalState>({
game: '',
show: false,
Expand Down Expand Up @@ -399,6 +407,10 @@ export default React.memo(function Library(): JSX.Element {
)
}

if (showSupportOfflineOnly) {
library = library.filter((game) => game.canRunOffline)
}

if (!showNonAvailable) {
const nonAvailbleGames = storage.getItem('nonAvailableGames') || '[]'
const nonAvailbleGamesArray = JSON.parse(nonAvailbleGames)
Expand Down Expand Up @@ -486,7 +498,8 @@ export default React.memo(function Library(): JSX.Element {
hiddenGames,
showFavouritesLibrary,
showInstalledOnly,
showNonAvailable
showNonAvailable,
showSupportOfflineOnly
])

// we need this to do proper `position: sticky` of the Add Game area
Expand Down Expand Up @@ -556,6 +569,8 @@ export default React.memo(function Library(): JSX.Element {
setShowNonAvailable: handleShowNonAvailable,
setSortDescending: handleSortDescending,
setSortInstalled: handleSortInstalled,
showSupportOfflineOnly,
setShowSupportOfflineOnly: handleShowSupportOfflineOnly,
sortDescending,
sortInstalled
}}
Expand Down
4 changes: 3 additions & 1 deletion src/frontend/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ export interface LibraryContextType {
sortDescending: boolean
setSortDescending: (value: boolean) => void
sortInstalled: boolean
setSortInstalled: (valur: boolean) => void
setSortInstalled: (value: boolean) => void
showSupportOfflineOnly: boolean
setShowSupportOfflineOnly: (value: boolean) => void
}

export interface GameContextType {
Expand Down