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

[WIP] Implement image rotation in frontend #200

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
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
25 changes: 24 additions & 1 deletion src/actions/photosActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Dispatch } from "redux";
import { z } from "zod";

// eslint-disable-next-line import/no-cycle
import { Server } from "../api_client/apiClient";
import { Server, serverAddress } from "../api_client/apiClient";
import i18n from "../i18n";
// eslint-disable-next-line import/no-cycle
import { PhotosetType } from "../reducers/photosReducer";
Expand Down Expand Up @@ -635,3 +635,26 @@ export function editPhoto(image_hash: string, photo_details: any) {
});
};
}

export function rotatePhoto(image_hash: string, angle: number, flip: boolean = false) {
return function (dispatch: Dispatch<any>) {
Server.post("photosedit/rotate", { image_hash: image_hash, angle: angle, flip: flip })
.then(() => {
dispatch({ type: "ROTATE_PHOTO_FULFILLED" });
dispatch(fetchPhotoDetail(image_hash));
showNotification({
message: i18n.t<string>("toasts.rotatephoto"),
title: i18n.t<string>("toasts.rotateupdate"),
color: "teal",
});
// Reset the cache
fetch(`${serverAddress}/media/thumbnails_big/${image_hash}`, {cache: 'reload', credentials: 'include'});
fetch(`${serverAddress}/media/square_thumbnails/${image_hash}`, {cache: 'reload', credentials: 'include'});
fetch(`${serverAddress}/media/square_thumbnails_small/${image_hash}`, {cache: 'reload', credentials: 'include'});
})
.catch(error => {
dispatch({ type: "ROTATE_PHOTO_REJECTED" });
console.error(error);
});
};
}
37 changes: 35 additions & 2 deletions src/components/lightbox/Toolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ActionIcon, Group, Loader } from "@mantine/core";
import React from "react";
import { Eye, EyeOff, Globe, InfoCircle, PlayerPause, PlayerPlay, Star } from "tabler-icons-react";
import { Eye, EyeOff, Globe, InfoCircle, PlayerPause, PlayerPlay, Star, RotateClockwise2, Rotate2 } from "tabler-icons-react";

import { setPhotosFavorite, setPhotosHidden, setPhotosPublic } from "../../actions/photosActions";
import { rotatePhoto, setPhotosFavorite, setPhotosHidden, setPhotosPublic } from "../../actions/photosActions";
import { shareAddress } from "../../api_client/apiClient";
import { playerActions } from "../../store/player/playerSlice";
import { useAppDispatch, useAppSelector } from "../../store/store";
Expand Down Expand Up @@ -42,6 +42,17 @@ export function Toolbar(props: Props) {

return (
<Group style={{ paddingBottom: 10, paddingRight: 5 }}>

{!photosDetail && (
<ActionIcon loading disabled={isPublic}>
<Rotate2 color="grey" />
</ActionIcon>
)}
{!photosDetail && (
<ActionIcon loading disabled={isPublic}>
<RotateClockwise2 color="grey" />
</ActionIcon>
)}
{!photosDetail && (
<ActionIcon loading disabled={isPublic}>
<Eye color="grey" />
Expand All @@ -58,6 +69,28 @@ export function Toolbar(props: Props) {
</ActionIcon>
)}
{playButton(photosDetail)}
{photosDetail && (
<ActionIcon
disabled={isPublic}
onClick={() => {
const { image_hash: imageHash } = photosDetail;
dispatch(rotatePhoto(imageHash, -90));
}}
>
<Rotate2 color="grey" />
</ActionIcon>
)}
{photosDetail && (
<ActionIcon
disabled={isPublic}
onClick={() => {
const { image_hash: imageHash } = photosDetail;
dispatch(rotatePhoto(imageHash, 90));
}}
>
<RotateClockwise2 color="grey" />
</ActionIcon>
)}
{photosDetail && (
<ActionIcon
disabled={isPublic}
Expand Down
4 changes: 3 additions & 1 deletion src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,9 @@
"removefacestoperson": "{{numberOfFaces}} face(s) were moved to 'Unknown - Other'",
"removefacestopersontitle": "Remove faces from person",
"savecaptions": "Image caption updated successfully",
"captionupdate": "Update Caption"
"captionupdate": "Update Caption",
"rotatephoto": "Photo rotated successfully",
"rotateupdate": "Rotate photo"
},
"rules": {
"1": "Local time from DATE_TIME_ORIGINAL exif tag",
Expand Down