Add global delete photo tag action

This commit is contained in:
Sam Becker 2023-10-05 11:31:49 -05:00
parent 52fe191d98
commit 3c913c273f
3 changed files with 11 additions and 2 deletions

2
src/cache/index.ts vendored
View File

@ -19,7 +19,7 @@ import { Camera, createCameraKey } from '@/camera';
const TAG_PHOTOS = 'photos';
const TAG_PHOTOS_COUNT = `${TAG_PHOTOS}-count`;
const TAG_PHOTOS_DATE_RANGE = `${TAG_PHOTOS}-date-range`;;
const TAG_PHOTOS_DATE_RANGE = `${TAG_PHOTOS}-date-range`;
const TAG_TAGS = 'tags';
const TAG_CAMERAS = 'cameras';
const TAG_BLOB = 'blob';

View File

@ -3,6 +3,7 @@
import {
sqlDeletePhoto,
sqlInsertPhoto,
sqlDeletePhotoTagGlobally,
sqlUpdatePhoto,
} from '@/services/postgres';
import { convertFormDataToPhoto } from './form';
@ -62,6 +63,14 @@ export async function deletePhotoAction(formData: FormData) {
revalidatePhotosTag();
};
export async function deletePhotoTagGloballyAction(formData: FormData) {
const tag = formData.get('tag') as string;
await sqlDeletePhotoTagGlobally(tag);
revalidatePhotosTag();
}
export async function deleteBlobPhotoAction(formData: FormData) {
await deleteBlobPhoto(formData.get('url') as string);

View File

@ -132,7 +132,7 @@ export const sqlUpdatePhoto = (photo: PhotoDbInsert) =>
WHERE id=${photo.id}
`;
export const sqlRemovePhotoTag = (tag: string) =>
export const sqlDeletePhotoTagGlobally = (tag: string) =>
sql`
UPDATE photos
SET tags=array_remove(tags, ${tag})