Skip to content

Commit

Permalink
Add "toolbar" buttons for some list actions (#1673)
Browse files Browse the repository at this point in the history
* Support adding buttons to list "toolbar"
* Show add and remove images to gallery in toolbar
* Show button to play selected scenes to list toolbar
  • Loading branch information
gitgiggety authored Aug 26, 2021
1 parent e98302f commit 2e83405
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 30 deletions.
1 change: 1 addition & 0 deletions ui/v2.5/src/components/Changelog/versions/v090.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Added not equals/greater than/less than modifiers for resolution criteria. ([#1568](https://github.com/stashapp/stash/pull/1568))

### 🎨 Improvements
* Move Play Selected Scenes, and Add/Remove Gallery Image buttons to button toolbar. ([#1673](https://github.com/stashapp/stash/pull/1673))
* Add image and gallery counts to tag list view. ([#1672](https://github.com/stashapp/stash/pull/1672))
* Prompt when leaving gallery edit page with unsaved changes. ([#1654](https://github.com/stashapp/stash/pull/1654))
* Show largest duplicates first in scene duplicate checker. ([#1639](https://github.com/stashapp/stash/pull/1639))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { mutateAddGalleryImages } from "src/core/StashService";
import { useToast } from "src/hooks";
import { TextUtils } from "src/utils";
import { useIntl } from "react-intl";
import { IconProp } from "@fortawesome/fontawesome-svg-core";

interface IGalleryAddProps {
gallery: Partial<GQL.GalleryDataFragment>;
Expand Down Expand Up @@ -87,6 +88,7 @@ export const GalleryAddPanel: React.FC<IGalleryAddProps> = ({ gallery }) => {
onClick: addImages,
isDisplayed: showWhenSelected,
postRefetch: true,
icon: "plus" as IconProp,
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { showWhenSelected, PersistanceLevel } from "src/hooks/ListHook";
import { useToast } from "src/hooks";
import { TextUtils } from "src/utils";
import { useIntl } from "react-intl";
import { IconProp } from "@fortawesome/fontawesome-svg-core";

interface IGalleryDetailsProps {
gallery: GQL.GalleryDataFragment;
Expand Down Expand Up @@ -81,6 +82,8 @@ export const GalleryImagesPanel: React.FC<IGalleryDetailsProps> = ({
onClick: removeImages,
isDisplayed: showWhenSelected,
postRefetch: true,
icon: "minus" as IconProp,
buttonVariant: "danger",
},
];

Expand Down
79 changes: 49 additions & 30 deletions ui/v2.5/src/components/List/ListOperationButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import {
} from "react-bootstrap";
import Mousetrap from "mousetrap";
import { FormattedMessage, useIntl } from "react-intl";
import { IconProp } from "@fortawesome/fontawesome-svg-core";
import { Icon } from "../Shared";

interface IListFilterOperation {
text: string;
onClick: () => void;
isDisplayed?: () => boolean;
icon?: IconProp;
buttonVariant?: string;
}

interface IListOperationButtonsProps {
Expand Down Expand Up @@ -60,37 +63,53 @@ export const ListOperationButtons: React.FC<IListOperationButtonsProps> = ({
};
});

function maybeRenderSelectedButtons() {
if (itemsSelected && (onEdit || onDelete)) {
function maybeRenderButtons() {
const buttons = (otherOperations ?? []).filter((o) => {
if (!o.icon) {
return false;
}

if (!o.isDisplayed) {
return true;
}

return o.isDisplayed();
});
if (itemsSelected) {
if (onEdit) {
buttons.push({
icon: "pencil-alt",
text: intl.formatMessage({ id: "actions.edit" }),
onClick: onEdit,
});
}
if (onDelete) {
buttons.push({
icon: "trash",
text: intl.formatMessage({ id: "actions.delete" }),
onClick: onDelete,
buttonVariant: "danger",
});
}
}

if (buttons.length > 0) {
return (
<ButtonGroup className="ml-2 mb-1">
{onEdit && (
<OverlayTrigger
overlay={
<Tooltip id="edit">
{intl.formatMessage({ id: "actions.edit" })}
</Tooltip>
}
>
<Button variant="secondary" onClick={onEdit}>
<Icon icon="pencil-alt" />
</Button>
</OverlayTrigger>
)}

{onDelete && (
<OverlayTrigger
overlay={
<Tooltip id="delete">
{intl.formatMessage({ id: "actions.delete" })}
</Tooltip>
}
>
<Button variant="danger" onClick={onDelete}>
<Icon icon="trash" />
</Button>
</OverlayTrigger>
)}
{buttons.map((button) => {
return (
<OverlayTrigger
overlay={<Tooltip id="edit">{button.text}</Tooltip>}
>
<Button
variant={button.buttonVariant ?? "secondary"}
onClick={button.onClick}
>
<Icon icon={button.icon as IconProp} />
</Button>
</OverlayTrigger>
);
})}
</ButtonGroup>
);
}
Expand Down Expand Up @@ -165,7 +184,7 @@ export const ListOperationButtons: React.FC<IListOperationButtonsProps> = ({

return (
<>
{maybeRenderSelectedButtons()}
{maybeRenderButtons()}

<div className="mx-2">{renderMore()}</div>
</>
Expand Down
2 changes: 2 additions & 0 deletions ui/v2.5/src/components/Scenes/SceneList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import _ from "lodash";
import { useIntl } from "react-intl";
import { useHistory } from "react-router-dom";
import Mousetrap from "mousetrap";
import { IconProp } from "@fortawesome/fontawesome-svg-core";
import {
FindScenesQueryResult,
SlimSceneDataFragment,
Expand Down Expand Up @@ -44,6 +45,7 @@ export const SceneList: React.FC<ISceneList> = ({
text: intl.formatMessage({ id: "actions.play_selected" }),
onClick: playSelected,
isDisplayed: showWhenSelected,
icon: "play" as IconProp,
},
{
text: intl.formatMessage({ id: "actions.play_random" }),
Expand Down
5 changes: 5 additions & 0 deletions ui/v2.5/src/hooks/ListHook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React, {
import { ApolloError } from "@apollo/client";
import { useHistory, useLocation } from "react-router-dom";
import Mousetrap from "mousetrap";
import { IconProp } from "@fortawesome/fontawesome-svg-core";
import {
SlimSceneDataFragment,
SceneMarkerDataFragment,
Expand Down Expand Up @@ -96,6 +97,8 @@ export interface IListHookOperation<T> {
selectedIds: Set<string>
) => boolean;
postRefetch?: boolean;
icon?: IconProp;
buttonVariant?: string;
}

export enum PersistanceLevel {
Expand Down Expand Up @@ -357,6 +360,8 @@ const RenderList = <

return true;
},
icon: o.icon,
buttonVariant: o.buttonVariant,
}));

function onEdit() {
Expand Down

0 comments on commit 2e83405

Please sign in to comment.