Skip to content

Commit

Permalink
Add "reshuffle button" when sortby is random (stashapp#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
FleetingOrchard authored Apr 24, 2020
1 parent 897b75e commit 5723504
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ui/v2.5/src/components/List/ListFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface IListFilterProps {
onChangeQuery: (query: string) => void;
onChangeSortDirection: (sortDirection: SortDirectionEnum) => void;
onChangeSortBy: (sortBy: string) => void;
onSortReshuffle: () => void;
onChangeDisplayMode: (displayMode: DisplayMode) => void;
onAddCriterion: (criterion: Criterion, oldId?: string) => void;
onRemoveCriterion: (criterion: Criterion) => void;
Expand Down Expand Up @@ -77,6 +78,10 @@ export const ListFilter: React.FC<IListFilterProps> = (
props.onChangeSortBy(target.text);
}

function onReshuffleRandomSort() {
props.onSortReshuffle();
}

function onChangeDisplayMode(displayMode: DisplayMode) {
props.onChangeDisplayMode(displayMode);
}
Expand Down Expand Up @@ -318,6 +323,17 @@ export const ListFilter: React.FC<IListFilterProps> = (
/>
</Button>
</OverlayTrigger>
{props.filter.sortBy === "random" && (
<OverlayTrigger
overlay={
<Tooltip id="sort-reshuffle-tooltip">Reshuffle</Tooltip>
}
>
<Button variant="secondary" onClick={onReshuffleRandomSort}>
<Icon icon="random" />
</Button>
</OverlayTrigger>
)}
</Dropdown>
</ButtonGroup>

Expand Down
8 changes: 8 additions & 0 deletions ui/v2.5/src/hooks/ListHook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ const useList = <QueryResult extends IQueryResult, QueryData extends IDataItem>(
updateQueryParams(newFilter);
}

function onSortReshuffle() {
const newFilter = _.cloneDeep(filter);
newFilter.currentPage = 1;
newFilter.randomSeed = -1;
updateQueryParams(newFilter);
}

function onChangeDisplayMode(displayMode: DisplayMode) {
const newFilter = _.cloneDeep(filter);
newFilter.displayMode = displayMode;
Expand Down Expand Up @@ -370,6 +377,7 @@ const useList = <QueryResult extends IQueryResult, QueryData extends IDataItem>(
onChangeQuery={onChangeQuery}
onChangeSortDirection={onChangeSortDirection}
onChangeSortBy={onChangeSortBy}
onSortReshuffle={onSortReshuffle}
onChangeDisplayMode={onChangeDisplayMode}
onAddCriterion={onAddCriterion}
onRemoveCriterion={onRemoveCriterion}
Expand Down

0 comments on commit 5723504

Please sign in to comment.