Skip to content

Commit

Permalink
feat: Platform and Play Mode adv filters
Browse files Browse the repository at this point in the history
  • Loading branch information
colin969 committed Jul 31, 2024
1 parent 94fd310 commit d2b7324
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 28 deletions.
1 change: 1 addition & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@
"busy": "Please Wait...",
"openGameDataBrowser": "Open Game Data Browser",
"allGenericEntries": "All Entries",
"usePlaylistOrder": "Use Playlist Order",
"notArchived": "Not Archived",
"archived": "Archived",
"playOnline": "Play Online"
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ export class Header extends React.Component<HeaderProps, HeaderState> {
customViews,
}, true);
this.props.searchActions.addViews({
views: [name]
views: [name],
areLibraries: false,
});
setTimeout(() => {
this.props.history.push(joinLibraryRoute(name));
Expand Down
42 changes: 30 additions & 12 deletions src/renderer/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import { ArrowKeyStepper, AutoSizer, List, ListRowProps } from 'react-virtualize
import { AdvancedFilter } from 'flashpoint-launcher';
import { useContext } from 'react';
import { LangContext } from '@renderer/util/lang';
import { useAppSelector } from '@renderer/hooks/useAppSelector';

export type SearchBarProps = {
libraries: string[];
};
export type SearchBarProps = {};

export function SearchBar(props: SearchBarProps) {
const view = useView();
const dispatch = useDispatch();
const [expanded, setExpanded] = React.useState(true);
const strings = useContext(LangContext);
const mainState = useAppSelector((state) => state.main);

const onTextChange = (event: React.ChangeEvent<HTMLInputElement>) => {
dispatch(setSearchText({
Expand Down Expand Up @@ -113,8 +113,14 @@ export function SearchBar(props: SearchBarProps) {
};
};

const onToggleLibrary = onToggleFactory('libraries');
const onClearLibraries = onClearFactory('libraries');
const onToggleLibrary = onToggleFactory('library');
const onClearLibraries = onClearFactory('library');

const onTogglePlayMode = onToggleFactory('playMode');
const onClearPlayMode = onClearFactory('playMode');

const onTogglePlatform = onToggleFactory('platform');
const onClearPlatform = onClearFactory('platform');

return (
<div className={`search-bar-wrapper ${expanded ? 'search-bar-wrapper--expanded-simple' : ''}`}>
Expand All @@ -131,7 +137,7 @@ export function SearchBar(props: SearchBarProps) {
}
}}
ref={searchInputRef}
placeholder="Search"
placeholder={strings.app.searchPlaceholder}
className="search-bar-text-input"
value={view.text}
onChange={onTextChange} />
Expand All @@ -157,27 +163,39 @@ export function SearchBar(props: SearchBarProps) {
(
<div className='search-bar-expansion search-bar-expansion-simple'>
<ThreeStateCheckbox
title='Installed'
title={strings.browse.installed}
value={view.advancedFilter.installed}
onChange={onInstalledChange}/>
{ view.selectedPlaylist && (
<ThreeStateCheckbox
title="Use Playlist Order"
title={strings.browse.usePlaylistOrder}
value={view.advancedFilter.playlistOrder}
twoState={true}
onChange={onPlaylistOrderChange}/>
)}
{ window.Shared.preferences.data.useCustomViews && (
<SearchableSelect
title={'Libraries'}
items={props.libraries}
selected={view.advancedFilter.libraries}
title={strings.browse.library}
items={mainState.libraries}
selected={view.advancedFilter.library}
onToggle={onToggleLibrary}
onClear={onClearLibraries}
mapName={(item) => {
return strings.libraries[item] || item;
}}/>
)}
<SearchableSelect
title={strings.browse.playMode}
items={mainState.suggestions.playMode}
selected={view.advancedFilter.playMode}
onToggle={onTogglePlayMode}
onClear={onClearPlayMode} />
<SearchableSelect
title={strings.browse.platform}
items={mainState.suggestions.platforms}
selected={view.advancedFilter.platform}
onToggle={onTogglePlatform}
onClear={onClearPlatform} />
</div>
)
}
Expand Down Expand Up @@ -284,7 +302,7 @@ function SearchableSelect(props: SearchableSelectProps) {
</div>
{expanded && (
<SearchableSelectDropdown
items={items}
items={[...items].sort()}
onToggle={onToggle}
selected={selected}
mapName={mapName}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/pages/BrowsePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class BrowsePage extends React.Component<BrowsePageProps, BrowsePageState
</ResizableSidebar>
<div
className='game-browser__center'>
<SearchBar libraries={this.props.libraries} />
<SearchBar />
<div className='game-browser__center-results-container'>
{(() => {
if (this.props.preferencesData.browsePageLayout === BrowsePageLayout.grid) {
Expand Down
2 changes: 0 additions & 2 deletions src/renderer/store/search/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
import { BackIn, PageKeyset, SearchQuery } from '@shared/back/types';
import { VIEW_PAGE_SIZE } from '@shared/constants';
import { getDefaultAdvancedFilter, getDefaultGameSearch } from '@shared/search/util';
import { num } from '@shared/utils/Coerce';
import { updatePreferencesData } from '@shared/preferences/util';

export const GENERAL_VIEW_ID = '!general!';
Expand Down Expand Up @@ -479,7 +478,6 @@ const searchSlice = createSlice({
}
},
addData(state: SearchState, { payload }: PayloadAction<SearchAddDataAction>) {
const startTime = Date.now();
const data = payload.data;
console.log(payload);
const view = state.views[payload.view];
Expand Down
1 change: 1 addition & 0 deletions src/shared/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ const langTemplate = {
'busy',
'openGameDataBrowser',
'allGenericEntries',
'usePlaylistOrder',
] as const,
tags: [
'name',
Expand Down
2 changes: 1 addition & 1 deletion src/shared/preferences/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ function parseGameMetadataSource(parser: IObjectParserProp<GameMetadataSource>):

function parseAdvancedFilter(parser: IObjectParserProp<AdvancedFilter>, output: AdvancedFilter) {
parser.prop('installed', v => output.installed = v === undefined ? undefined : !!v, true);
parser.prop('libraries').arrayRaw((item, index) => output.libraries[index] = str(item));
parser.prop('library').arrayRaw((item, index) => output.library[index] = str(item));
parser.prop('playlistOrder', v => output.playlistOrder = !!v, true);
}

Expand Down
47 changes: 37 additions & 10 deletions src/shared/search/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GameFilter, GameSearch } from '@fparchive/flashpoint-archive';
import { FieldFilter, GameFilter, GameSearch } from '@fparchive/flashpoint-archive';
import { AdvancedFilter } from 'flashpoint-launcher';

export function getDefaultGameSearch(): GameSearch {
Expand All @@ -22,7 +22,9 @@ export function getDefaultGameSearch(): GameSearch {
export function getDefaultAdvancedFilter(library?: string): AdvancedFilter {
return {
playlistOrder: true,
libraries: library ? [library] : [],
library: library ? [library] : [],
playMode: [],
platform: [],
};
}

Expand All @@ -44,7 +46,9 @@ export function getDefaultGameFilter(): GameFilter {
export function isAdvFilterEmpty(advFilter: AdvancedFilter): boolean {
return (
advFilter.installed === undefined &&
advFilter.libraries.length === 0
advFilter.library.length === 0 &&
advFilter.playMode.length === 0 &&
advFilter.platform.length === 0
);
}

Expand All @@ -55,13 +59,36 @@ export function parseAdvancedFilter(advFilter: AdvancedFilter): GameFilter {
filter.boolComp.installed = advFilter.installed;
}

if (advFilter.libraries.length > 0) {
console.log(`setting libraries - ${advFilter.libraries.join(' ; ')}`);
const newFilter = getDefaultGameFilter();
newFilter.matchAny = true;
newFilter.exactWhitelist.library = advFilter.libraries;
filter.subfilters.push(newFilter);
}
const exactFunc = (key: keyof AdvancedFilter, fieldKey: keyof FieldFilter) => {
const val = advFilter[key] as string[];
if (val.length > 0) {
const newFilter = getDefaultGameFilter();
newFilter.matchAny = true;
newFilter.exactWhitelist[fieldKey] = val;
filter.subfilters.push(newFilter);
}
};

const nonExactFunc = (key: keyof AdvancedFilter, fieldKey: keyof FieldFilter) => {
const val = advFilter[key] as string[];
if (val.length > 0) {
if (val.length === 1 && val[0] === '') {
const newFilter = getDefaultGameFilter();
newFilter.matchAny = true;
newFilter.exactWhitelist[fieldKey] = [''];
filter.subfilters.push(newFilter);
} else {
const newFilter = getDefaultGameFilter();
newFilter.matchAny = true;
newFilter.whitelist[fieldKey] = val;
filter.subfilters.push(newFilter);
}
}
};

exactFunc('library', 'library');
exactFunc('platform', 'platforms');
nonExactFunc('playMode', 'playMode');

return filter;
}
Expand Down
4 changes: 3 additions & 1 deletion typings/flashpoint-launcher.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,9 @@ declare module 'flashpoint-launcher' {
type AdvancedFilter = {
installed?: boolean;
playlistOrder: boolean;
libraries: string[];
library: string[];
playMode: string[];
platform: string[];
}

enum ScreenshotPreviewMode {
Expand Down

0 comments on commit d2b7324

Please sign in to comment.