Fix loading issue in galleries and redirect on gallery creation (#857)

* Fix loading issue in galleries and redirect on gallery creation
* Add error messages when image/galleries aren't found
* Clean up gallery/image/performer/scene view states
* Simplify error messages
This commit is contained in:
InfiniteTF
2020-10-17 00:57:02 +02:00
committed by GitHub
parent bbc6c43201
commit cf003a55bf
12 changed files with 171 additions and 105 deletions

View File

@@ -12,7 +12,7 @@ import {
useSceneGenerateScreenshot,
} from "src/core/StashService";
import { GalleryViewer } from "src/components/Galleries/GalleryViewer";
import { LoadingIndicator, Icon } from "src/components/Shared";
import { ErrorMessage, LoadingIndicator, Icon } from "src/components/Shared";
import { useToast } from "src/hooks";
import { ScenePlayer } from "src/components/ScenePlayer";
import { TextUtils, JWUtils } from "src/utils";
@@ -39,8 +39,8 @@ export const Scene: React.FC = () => {
const [timestamp, setTimestamp] = useState<number>(getInitialTimestamp());
const [collapsed, setCollapsed] = useState(false);
const [scene, setScene] = useState<GQL.SceneDataFragment | undefined>();
const { data, error, loading } = useFindScene(id);
const scene = data?.findScene;
const {
data: sceneStreams,
error: streamableError,
@@ -59,10 +59,6 @@ export const Scene: React.FC = () => {
const queryParams = queryString.parse(location.search);
const autoplay = queryParams?.autoplay === "true";
useEffect(() => {
if (data?.findScene) setScene(data.findScene);
}, [data]);
function getInitialTimestamp() {
const params = queryString.parse(location.search);
const initialTimestamp = params?.t ?? "0";
@@ -72,17 +68,10 @@ export const Scene: React.FC = () => {
);
}
const updateOCounter = (newValue: number) => {
const modifiedScene = { ...scene } as GQL.SceneDataFragment;
modifiedScene.o_counter = newValue;
setScene(modifiedScene);
};
const onIncrementClick = async () => {
try {
setOLoading(true);
const result = await incrementO();
if (result.data) updateOCounter(result.data.sceneIncrementO);
await incrementO();
} catch (e) {
Toast.error(e);
} finally {
@@ -93,8 +82,7 @@ export const Scene: React.FC = () => {
const onDecrementClick = async () => {
try {
setOLoading(true);
const result = await decrementO();
if (result.data) updateOCounter(result.data.sceneDecrementO);
await decrementO();
} catch (e) {
Toast.error(e);
} finally {
@@ -105,8 +93,7 @@ export const Scene: React.FC = () => {
const onResetClick = async () => {
try {
setOLoading(true);
const result = await resetO();
if (result.data) updateOCounter(result.data.sceneResetO);
await resetO();
} catch (e) {
Toast.error(e);
} finally {
@@ -290,7 +277,6 @@ export const Scene: React.FC = () => {
<SceneEditPanel
isVisible={activeTabKey === "scene-edit-panel"}
scene={scene}
onUpdate={(newScene) => setScene(newScene)}
onDelete={() => setIsDeleteAlertOpen(true)}
/>
</Tab.Pane>
@@ -320,12 +306,10 @@ export const Scene: React.FC = () => {
return collapsed ? ">" : "<";
}
if (loading || streamableLoading || !scene || !data?.findScene) {
return <LoadingIndicator />;
}
if (error) return <div>{error.message}</div>;
if (streamableError) return <div>{streamableError.message}</div>;
if (loading || streamableLoading) return <LoadingIndicator />;
if (error) return <ErrorMessage error={error.message} />;
if (streamableError) return <ErrorMessage error={streamableError.message} />;
if (!scene) return <ErrorMessage error={`No scene found with id ${id}.`} />;
return (
<div className="row">