Skip to content

Commit

Permalink
Merge pull request #16654 from Nexus-Mods/fblo-search-bar
Browse files Browse the repository at this point in the history
added search bar to FBLO
  • Loading branch information
insomnious authored Dec 12, 2024
2 parents 82a8aed + 3940770 commit d63f2a0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as util from '../../../util/api';
import { ComponentEx } from '../../../util/ComponentEx';
import * as selectors from '../../../util/selectors';
import { DNDContainer, MainPage } from '../../../views/api';
import { log } from '../../../util/log';
import FilterBox from './FilterBox';

import { setFBLoadOrder } from '../actions/loadOrder';
import { IItemRendererProps, ILoadOrderGameInfo, LoadOrder,
Expand All @@ -28,6 +28,7 @@ interface IBaseState {
updating: boolean;
validationError: LoadOrderValidationError;
currentRefreshId: string;
filterText: string;
}

export interface IBaseProps {
Expand Down Expand Up @@ -76,6 +77,7 @@ class FileBasedLoadOrderPage extends ComponentEx<IProps, IComponentState> {
updating: false,
validationError: undefined,
currentRefreshId: '',
filterText: '',
});

this.mStaticButtons = [
Expand Down Expand Up @@ -182,7 +184,10 @@ class FileBasedLoadOrderPage extends ComponentEx<IProps, IComponentState> {
displayCheckboxes: gameEntry.toggleableEntries || false,
invalidEntries: validationError?.validationResult?.invalid,
};
accum.push(rendOps);
// Filter based on the filterText, matching on loEntry.name or other attributes as needed
if (loEntry.name.toLowerCase().includes(this.state.filterText.toLowerCase())) {
accum.push(rendOps);
}
return accum;
}, [])
: [];
Expand All @@ -197,7 +202,7 @@ class FileBasedLoadOrderPage extends ComponentEx<IProps, IComponentState> {
? this.renderWait()
: (enabled.length > 0)
? <DraggableList
disabled={this.props.disabled}
disabled={this.props.disabled || this.state.filterText !== ''}
itemTypeId='file-based-lo-draggable-entry'
id='mod-loadorder-draggable-list'
items={enabled}
Expand Down Expand Up @@ -226,6 +231,7 @@ class FileBasedLoadOrderPage extends ComponentEx<IProps, IComponentState> {
<MainPage.Body>
<Panel>
<PanelX.Body>
<FilterBox currentFilterValue={this.state.filterText} setFilter={this.onFilter} />
<DNDContainer style={{ height: '100%' }}>
<FlexLayout type='row' className='file-based-load-order-container'>
<FlexLayout.Flex className={listClasses.join(' ')}>
Expand All @@ -248,6 +254,8 @@ class FileBasedLoadOrderPage extends ComponentEx<IProps, IComponentState> {
this.nextState.validationError = undefined;
}

private onFilter = (filterText: string) => this.nextState.filterText = filterText;

private renderWait() {
return (
<div className='fblo-spinner-container'>
Expand All @@ -263,6 +271,16 @@ class FileBasedLoadOrderPage extends ComponentEx<IProps, IComponentState> {
}

private onApply = (ordered: IItemRendererProps[]) => {
const { t } = this.props;
if (this.state.filterText !== '') {
this.context.api.sendNotification({
type: 'warning',
message: t('Must clear filter to apply changes'),
allowSuppress: true,
id: 'fblo-filter-not-cleared',
});
return;
}
const { onSetOrder, onShowError, loadOrder, profile, validateLoadOrder } = this.props;
const newLO = ordered.map(item => item.loEntry);
validateLoadOrder(profile, newLO)
Expand Down
28 changes: 28 additions & 0 deletions src/extensions/file_based_loadorder/views/FilterBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable */
import React from 'react';
import { FormInput } from 'vortex-api';
import { useTranslation } from 'react-i18next';

interface IProps {
currentFilterValue: string;
setFilter(value: string): void;
}

const FilterBox: React.FC<IProps> = ({ currentFilterValue, setFilter }) => {
const [t] = useTranslation('common');
const applyFilter = React.useCallback((value: string) => setFilter(value), [setFilter]);
return (
<FormInput
type='search'
id='file-based-load-order-filter'
className='file-based-load-order-filter'
value={currentFilterValue}
placeholder={t('Search for a specific load order entry...')}
onChange={applyFilter}
debounceTimer={100}
clearable
/>
);
}

export default FilterBox;
4 changes: 4 additions & 0 deletions src/stylesheets/vortex/page-mod-load-order.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
}
}

#file-based-load-order-filter {
width: 49%;
margin-bottom: 8px;
}
.load-order-entry {

display: flex;
Expand Down

0 comments on commit d63f2a0

Please sign in to comment.