Skip to content

Commit e53aeae

Browse files
authored
Revert "[TM-3069] revert changes" (#2090)
* Revert "[TM-3069] revert changes (#2086)" This reverts commit be2b442. * [TM-2089] add position functionality for upload image
1 parent 65e7a64 commit e53aeae

27 files changed

Lines changed: 1169 additions & 60 deletions

File tree

src/components/elements/ImageGallery/ImageGallery.stories.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ const mockData: MediaDto[] = (() => {
4545
isCover: faker.datatype.boolean(),
4646
description: faker.lorem.sentence({ min: 4, max: 8 }),
4747
photographer: faker.person.fullName(),
48-
createdByUserName: faker.person.fullName()
48+
createdByUserName: faker.person.fullName(),
49+
profileImageScale: faker.number.int({ min: 1, max: 10 }),
50+
profileImagePosition: { x: faker.number.int({ min: 1, max: 10 }), y: faker.number.int({ min: 1, max: 10 }) }
4951
});
5052
}
5153
return data;

src/components/elements/ImageGallery/ImageGalleryItem.stories.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ export const Default: Story = {
4848
isCover: faker.datatype.boolean(),
4949
description: faker.lorem.sentence({ min: 4, max: 8 }),
5050
photographer: faker.person.fullName(),
51-
createdByUserName: faker.person.fullName()
51+
createdByUserName: faker.person.fullName(),
52+
profileImageScale: faker.number.int({ min: 1, max: 10 }),
53+
profileImagePosition: { x: faker.number.int({ min: 1, max: 10 }), y: faker.number.int({ min: 1, max: 10 }) }
5254
}
5355
}
5456
};

src/components/elements/ImageGallery/ImageGalleryItem.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,17 @@ const ImageGalleryItem: FC<ImageGalleryItemProps> = ({
5757
onDelete?.(data.uuid);
5858
}, [data.uuid, onDelete]);
5959
const setImageCover = useCallback(async () => {
60-
const result = await updateMedia({ isCover: true }, { id: data.uuid });
60+
const result = await updateMedia(
61+
{ isCover: true, profileImageScale: data.profileImageScale, profileImagePosition: data.profileImagePosition },
62+
{ id: data.uuid }
63+
);
6164
if (result) {
6265
openNotification("success", t("Success!"), t("Image set as cover successfully"));
6366
reloadGalleryImages?.();
6467
} else {
6568
openNotification("error", t("Error!"), t("Failed to set image as cover"));
6669
}
67-
}, [data.uuid, openNotification, reloadGalleryImages, t]);
70+
}, [data.profileImageScale, data.profileImagePosition, data.uuid, openNotification, reloadGalleryImages, t]);
6871
const openModalImageDetail = useCallback(() => {
6972
openModal(
7073
ModalId.MODAL_IMAGE_DETAIL,

src/components/elements/Inputs/FileInput/FilePreviewCard.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ const FilePreviewCard = ({
4141
(checked: boolean) => {
4242
if (file == null) return;
4343

44-
updateMedia({ isPublic: checked }, { id: file.uuid });
44+
updateMedia(
45+
{
46+
isPublic: checked,
47+
profileImageScale: file.profileImageScale!,
48+
profileImagePosition: file.profileImagePosition!
49+
},
50+
{ id: file.uuid }
51+
);
4552
},
4653
[file]
4754
);

src/components/elements/Inputs/FileInput/FilePreviewTable.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,14 @@ const FilePreviewTable: FC<FilePreviewTableProps> = ({ items, onDelete, updateFi
112112
updatedItems.forEach(item => updateFile?.(item));
113113

114114
if (checked) {
115-
await updateMedia({ isCover: checked }, { id: selectedItem.uuid });
115+
await updateMedia(
116+
{
117+
isCover: checked,
118+
profileImageScale: selectedItem.profileImageScale!,
119+
profileImagePosition: selectedItem.profileImagePosition!
120+
},
121+
{ id: selectedItem.uuid }
122+
);
116123
}
117124
} catch (error) {
118125
Log.error("Error updating cover status:", error);
@@ -127,7 +134,14 @@ const FilePreviewTable: FC<FilePreviewTableProps> = ({ items, onDelete, updateFi
127134
(item: Partial<UploadedFile>, checked: boolean) => {
128135
showLoader();
129136
try {
130-
updateMedia({ isPublic: checked }, { id: item.uuid });
137+
updateMedia(
138+
{
139+
isPublic: checked,
140+
profileImageScale: item.profileImageScale!,
141+
profileImagePosition: item.profileImagePosition!
142+
},
143+
{ id: item.uuid }
144+
);
131145
updateFile?.({ ...item, isPublic: checked });
132146
} catch (error) {
133147
Log.error("Error updating public status:", error);

src/components/elements/Map-mapbox/Map.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ export const MapContainer = ({
560560
};
561561

562562
const setImageCover = async (uuid: string) => {
563-
const result = await updateMedia({ isCover: true }, { id: uuid });
563+
const result = await updateMedia({ isCover: true, profileImageScale: 0, profileImagePosition: {} }, { id: uuid });
564564
if (result) {
565565
openNotification("success", t("Success!"), t("Image set as cover successfully"));
566566
setShouldRefetchMediaData(true);

src/components/extensive/Modal/ModalImageDetails.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ const ModalImageDetails: FC<ModalImageDetailProps> = ({
105105
photographer: formData.photographer,
106106
description: formData.description ?? undefined,
107107
isPublic: formData.is_public,
108-
isCover: formData.is_cover
108+
isCover: formData.is_cover,
109+
profileImageScale: data.profileImageScale,
110+
profileImagePosition: data.profileImagePosition
109111
},
110112
{ id: data.uuid }
111113
);
@@ -114,7 +116,10 @@ const ModalImageDetails: FC<ModalImageDetailProps> = ({
114116
}
115117

116118
if (formData.is_cover !== initialFormData.is_cover && formData.is_cover) {
117-
const result = updateMedia({ isCover: true }, { id: data.uuid });
119+
const result = updateMedia(
120+
{ isCover: true, profileImageScale: data.profileImageScale, profileImagePosition: data.profileImagePosition },
121+
{ id: data.uuid }
122+
);
118123
updatePromises.push(result);
119124
}
120125

src/connections/Media.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ export const downloadImage = (uuid: string): Promise<Blob> => exportImage.fetchB
3636

3737
export const prepareFileForUpload = async (
3838
file: File,
39-
isPublic = true
39+
isPublic = true,
40+
isCover = false,
41+
profileImageScale?: number,
42+
profileImagePosition?: { x: number; y: number }
4043
): Promise<WithFormData<MediaRequestAttributes>> => {
4144
let location: Awaited<ReturnType<typeof exifr.gps>> | undefined = undefined;
4245
try {
@@ -48,7 +51,15 @@ export const prepareFileForUpload = async (
4851
const formData = new FormData();
4952
formData.append("uploadFile", file);
5053
const { latitude, longitude } = location ?? { latitude: null, longitude: null };
51-
return { isPublic, lat: latitude, lng: longitude, formData };
54+
return {
55+
isPublic,
56+
lat: latitude,
57+
lng: longitude,
58+
isCover,
59+
profileImageScale: profileImageScale ?? null,
60+
profileImagePosition: profileImagePosition ?? null,
61+
formData
62+
};
5263
};
5364

5465
export const fileUploadOptions = (

src/connections/Organisation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { connectionHook, connectionLoader } from "@/connections/util/connectionShortcuts";
1111
import { deleterAsync } from "@/connections/util/resourceDeleter";
1212
import { resourceCreator, resourceUpdater } from "@/connections/util/resourceMutator";
13+
import { MediaDto } from "@/generated/v3/entityService/entityServiceSchemas";
1314
import {
1415
createUserAssociation,
1516
organisationCreation,
@@ -25,7 +26,6 @@ import {
2526
FinancialReportLightDto,
2627
FundingTypeDto,
2728
LeadershipDto,
28-
MediaDto,
2929
OrganisationFullDto,
3030
OrganisationLightDto,
3131
OrganisationUpdateAttributes,

src/generated/v3/entityService/entityServiceSchemas.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export type MediaDto = {
149149
photographer: string | null;
150150
createdByUserName: string | null;
151151
profileImageScale: number | null;
152+
profileImagePosition: Record<string, any> | null;
152153
};
153154

154155
export type ImpactStoryLightDto = {
@@ -640,6 +641,10 @@ export type MediaRequestBulkAttributes = {
640641
* The profile image scale
641642
*/
642643
profileImageScale: number | null;
644+
/**
645+
* The profile image position
646+
*/
647+
profileImagePosition: Record<string, any> | null;
643648
};
644649

645650
export type MediaRequestBulkData = {
@@ -678,6 +683,10 @@ export type MediaRequestAttributes = {
678683
* Whether the media is a cover
679684
*/
680685
isCover: boolean | null;
686+
/**
687+
* The profile image position
688+
*/
689+
profileImagePosition: Record<string, any> | null;
681690
};
682691

683692
export type MediaRequestData = {
@@ -718,6 +727,10 @@ export type MediaUpdateAttributes = {
718727
* The profile image scale
719728
*/
720729
profileImageScale: number | null;
730+
/**
731+
* The profile image position
732+
*/
733+
profileImagePosition: Record<string, any> | null;
721734
};
722735

723736
export type MediaData = {
@@ -1978,6 +1991,7 @@ export type EmbeddedMediaDto = {
19781991
description: string | null;
19791992
photographer: string | null;
19801993
profileImageScale: number | null;
1994+
profileImagePosition: Record<string, any> | null;
19811995
};
19821996

19831997
export type FinancialIndicatorDto = {

0 commit comments

Comments
 (0)