mirror of
https://github.com/stashapp/stash.git
synced 2026-04-19 13:31:15 +02:00
Add "Open Random" to performer list (#265)
Mostly cribbing directly off WithoutPants' work.
This commit is contained in:
parent
92837fe1f7
commit
7ce96cd02b
2 changed files with 37 additions and 0 deletions
|
|
@ -8,16 +8,40 @@ import { ListFilterModel } from "../../models/list-filter/filter";
|
|||
import { DisplayMode, FilterMode } from "../../models/list-filter/types";
|
||||
import { PerformerCard } from "./PerformerCard";
|
||||
import { PerformerListTable } from "./PerformerListTable";
|
||||
import { StashService } from "../../core/StashService";
|
||||
|
||||
interface IPerformerListProps extends IBaseProps {}
|
||||
|
||||
export const PerformerList: FunctionComponent<IPerformerListProps> = (props: IPerformerListProps) => {
|
||||
const otherOperations = [
|
||||
{
|
||||
text: "Open Random",
|
||||
onClick: getRandom,
|
||||
}
|
||||
];
|
||||
|
||||
const listData = ListHook.useList({
|
||||
filterMode: FilterMode.Performers,
|
||||
props,
|
||||
otherOperations: otherOperations,
|
||||
renderContent,
|
||||
});
|
||||
|
||||
async function getRandom(result: QueryHookResult<FindPerformersQuery, FindPerformersVariables>, filter: ListFilterModel) {
|
||||
if (result.data && result.data.findPerformers) {
|
||||
let count = result.data.findPerformers.count;
|
||||
let index = Math.floor(Math.random() * count);
|
||||
let filterCopy = _.cloneDeep(filter);
|
||||
filterCopy.itemsPerPage = 1;
|
||||
filterCopy.currentPage = index + 1;
|
||||
const singleResult = await StashService.queryFindPerformers(filterCopy);
|
||||
if (singleResult && singleResult.data && singleResult.data.findPerformers && singleResult.data.findPerformers.performers.length === 1) {
|
||||
let id = singleResult!.data!.findPerformers!.performers[0]!.id;
|
||||
props.history.push("/performers/" + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function renderContent(
|
||||
result: QueryHookResult<FindPerformersQuery, FindPerformersVariables>, filter: ListFilterModel) {
|
||||
if (!result.data || !result.data.findPerformers) { return; }
|
||||
|
|
|
|||
|
|
@ -182,6 +182,19 @@ export class StashService {
|
|||
});
|
||||
}
|
||||
|
||||
public static queryFindPerformers(filter: ListFilterModel) {
|
||||
let performerFilter = {};
|
||||
performerFilter = filter.makePerformerFilter();
|
||||
|
||||
return StashService.client.query<GQL.FindPerformersQuery>({
|
||||
query: GQL.FindPerformersDocument,
|
||||
variables: {
|
||||
filter: filter.makeFindFilter(),
|
||||
performer_filter: performerFilter,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static useFindGallery(id: string) { return GQL.useFindGallery({variables: {id}}); }
|
||||
public static useFindScene(id: string) { return GQL.useFindScene({variables: {id}}); }
|
||||
public static useFindPerformer(id: string) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue