Skip to content

Commit

Permalink
fix: Tags not searching correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
colin969 committed Jul 30, 2024
1 parent caa54f3 commit b582f84
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/renderer/components/RightBrowseSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1396,8 +1396,8 @@ export class RightBrowseSidebar extends React.Component<RightBrowseSidebarProps,
this.props.onDeselectPlaylist();
const value = this.props.currentGame[field as keyof Game]?.toString();
const search = (value)
? `${field}=${wrapSearchTerm(value)}`
: `${field}=""`;
? `${field}:${wrapSearchTerm(value)}`
: `${field}:""`;
this.props.onSearch(search);
}
};
Expand Down
13 changes: 11 additions & 2 deletions src/renderer/components/TagInputField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@ type TagInputFieldState = {
expanded: boolean;
};

function withModifiableTags<T extends TagInputFieldProps>(Component: React.ComponentType<T>) {
return function WithModifiableTags(props: T) {
const modifiableTags = [...props.tags];
return <Component {...props} tags={modifiableTags} />;
};
}

/** An input element with a drop-down menu that can list any number of selectable and clickable text elements. */
export class TagInputField extends React.Component<TagInputFieldProps, TagInputFieldState> {
class TagInputFieldRaw extends React.Component<TagInputFieldProps, TagInputFieldState> {
rootRef: React.RefObject<HTMLDivElement> = React.createRef();
contentRef: React.RefObject<HTMLDivElement> = React.createRef();
inputRef: React.RefObject<InputElement> = React.createRef();
Expand Down Expand Up @@ -155,7 +162,7 @@ export class TagInputField extends React.Component<TagInputFieldProps, TagInputF
/** Renders the list of items in the drop-down menu. */
renderItems = memoizeOne<(items: Tag[], primaryPlatform?: string) => JSX.Element[]>((items: Tag[], primaryPlatform?: string) => {
const className = this.props.editable ? 'tag-editable' : 'tag-static';
return [...items]
return items
.sort((t1, t2) => `${t1.category}-${t1.name}`.localeCompare(`${t2.category}-${t2.name}`))
.map((tag, index) => {
const category = this.props.categories.find(c => c.name == tag.category);
Expand Down Expand Up @@ -356,3 +363,5 @@ function checkIfArraysAreEqual(a: Array<any>, b: Array<any>): boolean {
}
return true;
}

export const TagInputField = withModifiableTags(TagInputFieldRaw);
10 changes: 4 additions & 6 deletions src/renderer/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1501,12 +1501,7 @@ export class App extends React.Component<AppProps> {
suggestions={this.props.main.suggestions}
busyGames={this.props.main.busyGames}
onFpfssEditGame={this.onFpfssEditGame}
onSearch={(text) => {
this.props.searchActions.setSearchText({
view: this.props.currentView.id,
text,
});
}}/>
onSearch={this.onSearch}/>
</ResizableSidebar>
)}
</div>
Expand Down Expand Up @@ -1805,6 +1800,9 @@ export class App extends React.Component<AppProps> {
view: this.props.currentView.id,
text,
});
this.props.searchActions.forceSearch({
view: this.props.currentView.id,
});
};

onApplyFpfssEditGame = (game: Partial<Game>) => {
Expand Down
1 change: 1 addition & 0 deletions src/renderer/store/search/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export const forceSearch = createAsyncThunk(
async (payload: ForceSearchAction, { getState, dispatch }) => {
const state = getState() as { search: SearchState };
const view = state.search.views[payload.view];
console.log('forced search');

const filter = await window.Shared.back.request(BackIn.PARSE_QUERY_DATA, {
viewId: payload.view,
Expand Down

0 comments on commit b582f84

Please sign in to comment.