Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add title, rating, o-counter to image lightbox #2274

Merged
merged 6 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ui/v2.5/src/components/Changelog/versions/v0130.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### ✨ New Features
* Added title, rating and o-counter in image lightbox. ([#2274](https://github.com/stashapp/stash/pull/2274))
* Added option to hide scene scrubber by default. ([#2325](https://github.com/stashapp/stash/pull/2325))
* Added support for bulk-editing movies. ([#2283](https://github.com/stashapp/stash/pull/2283))
* Added support for filtering scenes, images and galleries featuring favourite performers and performer age at time of production. ([#2257](https://github.com/stashapp/stash/pull/2257))
Expand Down
11 changes: 0 additions & 11 deletions ui/v2.5/src/components/Images/ImageDetails/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const Image: React.FC = () => {

const { data, error, loading } = useFindImage(id);
const image = data?.findImage;
const [oLoading, setOLoading] = useState(false);
const [incrementO] = useImageIncrementO(image?.id ?? "0");
const [decrementO] = useImageDecrementO(image?.id ?? "0");
const [resetO] = useImageResetO(image?.id ?? "0");
Expand Down Expand Up @@ -87,34 +86,25 @@ export const Image: React.FC = () => {

const onIncrementClick = async () => {
try {
setOLoading(true);
await incrementO();
} catch (e) {
Toast.error(e);
} finally {
setOLoading(false);
}
};

const onDecrementClick = async () => {
try {
setOLoading(true);
await decrementO();
} catch (e) {
Toast.error(e);
} finally {
setOLoading(false);
}
};

const onResetClick = async () => {
try {
setOLoading(true);
await resetO();
} catch (e) {
Toast.error(e);
} finally {
setOLoading(false);
}
};

Expand Down Expand Up @@ -196,7 +186,6 @@ export const Image: React.FC = () => {
</Nav.Item>
<Nav.Item className="ml-auto">
<OCounterButton
loading={oLoading}
value={image.o_counter || 0}
onIncrement={onIncrementClick}
onDecrement={onDecrementClick}
Expand Down
49 changes: 30 additions & 19 deletions ui/v2.5/src/components/Scenes/SceneDetails/OCounterButton.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
import React from "react";
import {
Button,
ButtonGroup,
Dropdown,
DropdownButton,
Spinner,
} from "react-bootstrap";
import React, { useState } from "react";
import { Button, ButtonGroup, Dropdown, DropdownButton } from "react-bootstrap";
import { useIntl } from "react-intl";
import { Icon, SweatDrops } from "src/components/Shared";
import { Icon, LoadingIndicator, SweatDrops } from "src/components/Shared";

export interface IOCounterButtonProps {
loading: boolean;
value: number;
onIncrement: () => void;
onDecrement: () => void;
onReset: () => void;
onMenuOpened?: () => void;
onMenuClosed?: () => void;
onIncrement: () => Promise<void>;
onDecrement: () => Promise<void>;
onReset: () => Promise<void>;
}

export const OCounterButton: React.FC<IOCounterButtonProps> = (
props: IOCounterButtonProps
) => {
const intl = useIntl();
if (props.loading) return <Spinner animation="border" role="status" />;
const [loading, setLoading] = useState(false);

async function increment() {
setLoading(true);
await props.onIncrement();
setLoading(false);
}

async function decrement() {
setLoading(true);
await props.onDecrement();
setLoading(false);
}

async function reset() {
setLoading(true);
await props.onReset();
setLoading(false);
}

if (loading) return <LoadingIndicator message="" inline small />;

const renderButton = () => (
<Button
className="minimal pr-1"
onClick={props.onIncrement}
onClick={increment}
variant="secondary"
title={intl.formatMessage({ id: "o_counter" })}
>
Expand All @@ -46,11 +57,11 @@ export const OCounterButton: React.FC<IOCounterButtonProps> = (
variant="secondary"
className="pl-0 show-carat"
>
<Dropdown.Item onClick={props.onDecrement}>
<Dropdown.Item onClick={decrement}>
<Icon icon="minus" />
<span>Decrement</span>
</Dropdown.Item>
<Dropdown.Item onClick={props.onReset}>
<Dropdown.Item onClick={reset}>
<Icon icon="ban" />
<span>Reset</span>
</Dropdown.Item>
Expand Down
11 changes: 0 additions & 11 deletions ui/v2.5/src/components/Scenes/SceneDetails/Scene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ const ScenePage: React.FC<IProps> = ({ scene, refetch }) => {
loading: streamableLoading,
} = useSceneStreams(scene.id);

const [oLoading, setOLoading] = useState(false);
const [incrementO] = useSceneIncrementO(scene.id);
const [decrementO] = useSceneDecrementO(scene.id);
const [resetO] = useSceneResetO(scene.id);
Expand Down Expand Up @@ -172,34 +171,25 @@ const ScenePage: React.FC<IProps> = ({ scene, refetch }) => {

const onIncrementClick = async () => {
try {
setOLoading(true);
await incrementO();
} catch (e) {
Toast.error(e);
} finally {
setOLoading(false);
}
};

const onDecrementClick = async () => {
try {
setOLoading(true);
await decrementO();
} catch (e) {
Toast.error(e);
} finally {
setOLoading(false);
}
};

const onResetClick = async () => {
try {
setOLoading(true);
await resetO();
} catch (e) {
Toast.error(e);
} finally {
setOLoading(false);
}
};

Expand Down Expand Up @@ -485,7 +475,6 @@ const ScenePage: React.FC<IProps> = ({ scene, refetch }) => {
</Nav.Item>
<Nav.Item className="ml-auto">
<OCounterButton
loading={oLoading}
value={scene.o_counter || 0}
onIncrement={onIncrementClick}
onDecrement={onDecrementClick}
Expand Down
53 changes: 48 additions & 5 deletions ui/v2.5/src/core/StashService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,21 +541,64 @@ const updateImageO = (
export const useImageIncrementO = (id: string) =>
GQL.useImageIncrementOMutation({
variables: { id },
update: (cache, data) =>
updateImageO(id, cache, data.data?.imageIncrementO),
update: (cache, data) => {
updateImageO(id, cache, data.data?.imageIncrementO);
// impacts FindImages as well as FindImage
deleteCache([GQL.FindImagesDocument])(cache);
},
});

export const mutateImageIncrementO = (id: string) =>
client.mutate<GQL.ImageIncrementOMutation>({
mutation: GQL.ImageIncrementODocument,
variables: { id },
update: (cache, data) => {
updateImageO(id, cache, data.data?.imageIncrementO);
// impacts FindImages as well as FindImage
deleteCache([GQL.FindImagesDocument])(cache);
},
});

export const useImageDecrementO = (id: string) =>
GQL.useImageDecrementOMutation({
variables: { id },
update: (cache, data) =>
updateImageO(id, cache, data.data?.imageDecrementO),
update: (cache, data) => {
updateImageO(id, cache, data.data?.imageDecrementO);
// impacts FindImages as well as FindImage
deleteCache([GQL.FindImagesDocument])(cache);
},
});

export const mutateImageDecrementO = (id: string) =>
client.mutate<GQL.ImageDecrementOMutation>({
mutation: GQL.ImageDecrementODocument,
variables: { id },
update: (cache, data) => {
updateImageO(id, cache, data.data?.imageDecrementO);
// impacts FindImages as well as FindImage
deleteCache([GQL.FindImagesDocument])(cache);
},
});

export const useImageResetO = (id: string) =>
GQL.useImageResetOMutation({
variables: { id },
update: (cache, data) => updateImageO(id, cache, data.data?.imageResetO),
update: (cache, data) => {
updateImageO(id, cache, data.data?.imageResetO);
// impacts FindImages as well as FindImage
deleteCache([GQL.FindImagesDocument])(cache);
},
});

export const mutateImageResetO = (id: string) =>
client.mutate<GQL.ImageResetOMutation>({
mutation: GQL.ImageResetODocument,
variables: { id },
update: (cache, data) => {
updateImageO(id, cache, data.data?.imageResetO);
// impacts FindImages as well as FindImage
deleteCache([GQL.FindImagesDocument])(cache);
},
});

const galleryMutationImpactedQueries = [
Expand Down
Loading