-
-
Notifications
You must be signed in to change notification settings - Fork 440
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
A lot of rendering refactors related to libraries (and a few extras) #1267
Changes from 1 commit
4485747
06b8628
95236a5
1725054
7697bf8
a35774b
6ab4fa1
e97ecf9
233500f
3c4a1d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ const Backend = new HttpApi(null, { | |
initGamepad() | ||
initShortcuts() | ||
|
||
const storage: Storage = window.localStorage | ||
|
||
i18next | ||
// load translation using http -> see /public/locales | ||
// learn more: https://github.com/i18next/i18next-http-backend | ||
|
@@ -32,7 +34,7 @@ i18next | |
interpolation: { | ||
escapeValue: false | ||
}, | ||
lng: 'en', | ||
lng: storage.getItem('language') || 'en', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when selecting a language other than |
||
react: { | ||
useSuspense: true | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
import './index.css' | ||
|
||
import React, { lazy, useContext, useEffect, useRef, useState } from 'react' | ||
import React, { | ||
lazy, | ||
useContext, | ||
useEffect, | ||
useMemo, | ||
useRef, | ||
useState | ||
} from 'react' | ||
|
||
import ContextProvider from 'src/state/ContextProvider' | ||
|
||
|
@@ -23,13 +30,19 @@ export default function Library(): JSX.Element { | |
layout, | ||
libraryStatus, | ||
refreshing, | ||
refreshingInTheBackground, | ||
category, | ||
filter, | ||
epicLibrary, | ||
gogLibrary, | ||
recentGames, | ||
favouriteGames, | ||
libraryTopSection | ||
libraryTopSection, | ||
filterText, | ||
platform, | ||
filterPlatform, | ||
hiddenGames, | ||
showHidden | ||
} = useContext(ContextProvider) | ||
|
||
const [showModal, setShowModal] = useState({ | ||
|
@@ -109,26 +122,114 @@ export default function Library(): JSX.Element { | |
setInstalling(newInstalling) | ||
}, [libraryStatus]) | ||
|
||
// select library and sort | ||
let libraryToShow = category === 'epic' ? epicLibrary : gogLibrary | ||
libraryToShow = libraryToShow.sort( | ||
(a: { title: string }, b: { title: string }) => { | ||
const filterLibrary = (library: GameInfo[], filter: string) => { | ||
if (!library) { | ||
return [] | ||
} | ||
|
||
if (filter.includes('UE_')) { | ||
return library.filter((game) => { | ||
if (!game.compatible_apps) { | ||
return false | ||
} | ||
return game.compatible_apps.includes(filter) | ||
}) | ||
} else { | ||
switch (filter) { | ||
case 'unreal': | ||
return library.filter( | ||
(game) => | ||
game.is_ue_project || game.is_ue_asset || game.is_ue_plugin | ||
) | ||
case 'asset': | ||
return library.filter((game) => game.is_ue_asset) | ||
case 'plugin': | ||
return library.filter((game) => game.is_ue_plugin) | ||
case 'project': | ||
return library.filter((game) => game.is_ue_project) | ||
default: | ||
return library.filter((game) => game.is_game) | ||
} | ||
} | ||
} | ||
|
||
const filterByPlatform = (library: GameInfo[], filter: string) => { | ||
if (category === 'epic' && platform === 'linux') { | ||
return library.filter((game) => game.is_game) | ||
} | ||
|
||
switch (filter) { | ||
case 'win': | ||
return library.filter((game) => | ||
process.platform == 'darwin' | ||
? !game.is_mac_native | ||
: !game.is_linux_native | ||
) | ||
case 'mac': | ||
return library.filter((game) => game.is_mac_native) | ||
case 'linux': | ||
return library.filter((game) => game.is_linux_native) | ||
default: | ||
return library.filter((game) => game.is_game) | ||
} | ||
} | ||
|
||
// select library | ||
const libraryToShow = useMemo(() => { | ||
let library = category === 'epic' ? epicLibrary : gogLibrary | ||
|
||
// filter | ||
try { | ||
const filterRegex = new RegExp(filterText, 'i') | ||
const textFilter = ({ title, app_name }: GameInfo) => | ||
filterRegex.test(title) || filterRegex.test(app_name) | ||
library = filterByPlatform( | ||
filterLibrary(library, filter).filter(textFilter), | ||
filterPlatform | ||
) | ||
} catch (error) { | ||
console.log(error) | ||
} | ||
|
||
// hide hidden | ||
const hiddenGamesAppNames = hiddenGames.list.map((hidden) => hidden.appName) | ||
|
||
if (!showHidden) { | ||
library = library.filter( | ||
(game) => !hiddenGamesAppNames.includes(game.app_name) | ||
) | ||
} | ||
|
||
// sort | ||
library = library.sort((a: { title: string }, b: { title: string }) => { | ||
const gameA = a.title.toUpperCase().replace('THE ', '') | ||
const gameB = b.title.toUpperCase().replace('THE ', '') | ||
return sortDescending ? (gameA > gameB ? -1 : 1) : gameA < gameB ? -1 : 1 | ||
} | ||
) | ||
const installed = libraryToShow.filter((g) => g.is_installed) | ||
const notInstalled = libraryToShow.filter( | ||
(g) => !g.is_installed && !installing.includes(g.app_name) | ||
) | ||
const installingGames = libraryToShow.filter((g) => | ||
installing.includes(g.app_name) | ||
) | ||
libraryToShow = sortInstalled | ||
? [...installed, ...installingGames, ...notInstalled] | ||
: libraryToShow | ||
}) | ||
const installed = library.filter((g) => g.is_installed) | ||
const notInstalled = library.filter( | ||
(g) => !g.is_installed && !installing.includes(g.app_name) | ||
) | ||
const installingGames = library.filter((g) => | ||
installing.includes(g.app_name) | ||
) | ||
library = sortInstalled | ||
? [...installed, ...installingGames, ...notInstalled] | ||
: library | ||
|
||
return library | ||
}, [ | ||
category, | ||
epicLibrary, | ||
gogLibrary, | ||
filter, | ||
filterText, | ||
filterPlatform, | ||
sortDescending, | ||
sortInstalled | ||
]) | ||
|
||
// top section | ||
const showRecentGames = | ||
libraryTopSection === 'recently_played' && | ||
!!recentGames.length && | ||
|
@@ -139,29 +240,25 @@ export default function Library(): JSX.Element { | |
!!favouriteGames.list.length && | ||
category !== 'unreal' | ||
|
||
const favourites: GameInfo[] = [] | ||
|
||
if (showFavourites) { | ||
const favouriteAppNames = favouriteGames.list.map( | ||
(favourite) => favourite.appName | ||
) | ||
epicLibrary.forEach((game) => { | ||
if (favouriteAppNames.includes(game.app_name)) favourites.push(game) | ||
}) | ||
gogLibrary.forEach((game) => { | ||
if (favouriteAppNames.includes(game.app_name)) favourites.push(game) | ||
}) | ||
} | ||
|
||
const dlcCount = epicLibrary.filter((lib) => lib.install.is_dlc) | ||
const numberOfGames = | ||
category == 'epic' | ||
? epicLibrary.length - dlcCount.length | ||
: gogLibrary.length | ||
const favourites: GameInfo[] = useMemo(() => { | ||
const tempArray: GameInfo[] = [] | ||
if (showFavourites) { | ||
const favouriteAppNames = favouriteGames.list.map( | ||
(favourite) => favourite.appName | ||
) | ||
epicLibrary.forEach((game) => { | ||
if (favouriteAppNames.includes(game.app_name)) tempArray.push(game) | ||
}) | ||
gogLibrary.forEach((game) => { | ||
if (favouriteAppNames.includes(game.app_name)) tempArray.push(game) | ||
}) | ||
} | ||
return tempArray | ||
}, [showFavourites, favouriteGames, epicLibrary, gogLibrary]) | ||
|
||
return ( | ||
<> | ||
<Header numberOfGames={numberOfGames} /> | ||
<Header /> | ||
|
||
<div className="listing"> | ||
<span id="top" /> | ||
|
@@ -184,9 +281,9 @@ export default function Library(): JSX.Element { | |
|
||
<h3 className="libraryHeader">{titleWithIcons()}</h3> | ||
|
||
{refreshing && <UpdateComponent inline />} | ||
{refreshing && !refreshingInTheBackground && <UpdateComponent inline />} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this |
||
|
||
{!refreshing && ( | ||
{(!refreshing || refreshingInTheBackground) && ( | ||
<GamesList | ||
library={libraryToShow} | ||
layout={layout} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
refresh
function called right after this line also prints this same string to the logs, it gave the impression that the epic library was getting refreshed twice when it didn't.