-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da51192
commit 69357f2
Showing
18 changed files
with
229 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { createSelector, createSlice } from '@reduxjs/toolkit' | ||
import NoFilter from '../../../domain/filters/NoFilter' | ||
import MatchName from '../../../domain/filters/playnite/MatchName' | ||
|
||
import _ from 'lodash' | ||
|
||
const { memoize, merge } = _ | ||
|
||
const initialState: { | ||
nameFilter: string | null | ||
} = { | ||
nameFilter: null, | ||
} | ||
|
||
const noFilter = new NoFilter() | ||
|
||
const getNameFilter = memoize((state: typeof initialState) => | ||
!state.nameFilter ? noFilter : new MatchName(state.nameFilter), | ||
) | ||
|
||
const slice = createSlice({ | ||
name: 'library', | ||
initialState, | ||
selectors: { | ||
getFilter: createSelector(getNameFilter, (filter) => filter), | ||
}, | ||
reducers: { | ||
setNameFilter(state, action) { | ||
return merge({}, state, { nameFilter: action.payload }) | ||
}, | ||
}, | ||
}) | ||
|
||
export const { reducer } = slice | ||
export const { setNameFilter } = slice.actions | ||
export const { getFilter } = slice.selectors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { configureStore } from '@reduxjs/toolkit' | ||
import { reducer } from '.' | ||
|
||
let store | ||
const getStore = () => { | ||
if (!store) { | ||
store = configureStore({ reducer }) | ||
} | ||
|
||
return store | ||
} | ||
|
||
export default getStore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Divider, TextField, styled } from '@mui/material' | ||
import { ChangeEvent, FC, PropsWithChildren, useCallback } from 'react' | ||
import { useDispatch, useStore } from 'react-redux' | ||
import { setNameFilter } from '../api/client/state/librarySlice' | ||
|
||
const HeaderContainer = styled('header')(({ theme }) => ({ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
})) | ||
|
||
const Filters = styled('section')(({ theme }) => ({ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
flex: 1, | ||
justifyContent: 'flex-end', | ||
alignItems: 'flex-end', | ||
})) | ||
|
||
const Header: FC<PropsWithChildren<{ showFilters?: boolean }>> = ({ | ||
children, | ||
showFilters, | ||
}) => { | ||
const store = useStore() | ||
console.dir(store.getState()) | ||
const dispatch = useDispatch() | ||
const handleSearch = useCallback((event: ChangeEvent<HTMLInputElement>) => { | ||
dispatch(setNameFilter(event.target.value)) | ||
}, []) | ||
|
||
return ( | ||
<> | ||
<HeaderContainer> | ||
{children} | ||
{showFilters && ( | ||
<Filters> | ||
<TextField | ||
onChange={handleSearch} | ||
placeholder="Find" | ||
type="text" | ||
defaultValue="" | ||
variant="outlined" | ||
/> | ||
</Filters> | ||
)} | ||
</HeaderContainer> | ||
<Divider sx={{ margin: `48px 0` }} /> | ||
</> | ||
) | ||
} | ||
|
||
export default Header |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Typography } from '@mui/material' | ||
import { FC, useMemo } from 'react' | ||
import { Helmet } from 'react-helmet' | ||
import { useSelector } from 'react-redux' | ||
import { getFilter } from '../api/client/state/librarySlice' | ||
import GameGrid from '../components/GameGrid' | ||
import Header from '../components/Header' | ||
import FilteredGameList from '../domain/FilteredGameList' | ||
import GameList from '../domain/GameList' | ||
import type { GameOnPlatform } from '../domain/types' | ||
|
||
const MyLibrary: FC<{ gamesOnPlatforms: GameOnPlatform[] }> = ({ | ||
gamesOnPlatforms = [] as GameOnPlatform[], | ||
}) => { | ||
const gameList = useMemo(() => { | ||
return new GameList(gamesOnPlatforms) | ||
}, [gamesOnPlatforms]) | ||
|
||
const filter = useSelector(getFilter) | ||
const filteredGames = useMemo( | ||
() => new FilteredGameList(gameList, filter), | ||
[gameList, filter], | ||
) | ||
|
||
const noDeferCount = 25 | ||
|
||
return ( | ||
<> | ||
<Helmet> | ||
{gameList.items | ||
.filter((game, index) => index <= noDeferCount) | ||
.map((game) => ( | ||
<link | ||
key={game.oid.asString} | ||
rel="preload" | ||
as="image" | ||
href={game.cover} | ||
/> | ||
))} | ||
</Helmet> | ||
<Header showFilters> | ||
<section> | ||
<Typography variant="h2">My Games</Typography> | ||
<Typography variant="subtitle1"> | ||
{gameList.items.length} games in my library | ||
</Typography> | ||
</section> | ||
</Header> | ||
<GameGrid games={filteredGames} noDeferCount={noDeferCount} /> | ||
</> | ||
) | ||
} | ||
|
||
export default MyLibrary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.