Skip to content

Commit

Permalink
Merge pull request #153 from 0101oak/oak/fix-media-selector
Browse files Browse the repository at this point in the history
media can be deleted only from media selector
  • Loading branch information
ijustseeblood authored Oct 24, 2024
2 parents f2f2ec6 + 40967de commit a08dae1
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/components/common/singleMediaViewAndSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface SingleMediaView {
isAddingProduct?: boolean;
aspectRatio?: string[];
hideVideos?: boolean;
isDeleteAccepted?: boolean;
saveSelectedMedia: (newSelectedMedia: common_MediaFull[]) => void;
}

Expand All @@ -20,6 +21,7 @@ export const SingleMediaViewAndSelect: FC<SingleMediaView> = ({
isAddingProduct,
aspectRatio,
hideVideos,
isDeleteAccepted,
saveSelectedMedia,
}) => {
return (
Expand All @@ -38,6 +40,7 @@ export const SingleMediaViewAndSelect: FC<SingleMediaView> = ({
allowMultiple={false}
aspectRatio={aspectRatio}
hideVideos={hideVideos}
isDeleteAccepted={isDeleteAccepted}
saveSelectedMedia={saveSelectedMedia}
/>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export const CreateArchive: FC<createArchives> = ({ fetchArchive, showMessage })
saveSelectedMedia={mediaPreview}
aspectRatio={['1:1', '3:4', '4:3']}
hideVideos={true}
isDeleteAccepted={false}
/>
</Grid>
{mediaItem.map((media, id) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ export const ListArchive: FC<ListArchiveInterface> = ({
saveSelectedMedia={handleMediaPreview(entry.archive?.id)}
aspectRatio={['1:1', '3:4', '4:3']}
hideVideos={true}
isDeleteAccepted={false}
/>
</Grid>
)}
Expand Down
2 changes: 2 additions & 0 deletions src/components/managers/hero/entities/doubleAdd/doubleAdd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const DoubleAdd: FC<HeroMediaEntityInterface> = ({
<SingleMediaViewAndSelect
link={doubleLinks?.[index]?.left || ''}
aspectRatio={allowedRatios?.[index] || ['4:5', '1:1']}
isDeleteAccepted={false}
saveSelectedMedia={(selectedMedia) =>
saveDoubleMedia && saveDoubleMedia(selectedMedia, 'left', index)
}
Expand Down Expand Up @@ -68,6 +69,7 @@ export const DoubleAdd: FC<HeroMediaEntityInterface> = ({
<SingleMediaViewAndSelect
link={doubleLinks?.[index]?.right || ''}
aspectRatio={allowedRatios?.[index] || ['4:5', '1:1']}
isDeleteAccepted={false}
saveSelectedMedia={(selectedMedia) =>
saveDoubleMedia && saveDoubleMedia(selectedMedia, 'right', index)
}
Expand Down
1 change: 1 addition & 0 deletions src/components/managers/hero/entities/mainAdd/mainAdd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const MainAdd: FC<HeroMediaEntityInterface> = ({ index, entity, link, sav
<SingleMediaViewAndSelect
link={link}
aspectRatio={['4:5', '5:4', '1:1', '16:9', '9:16']}
isDeleteAccepted={false}
saveSelectedMedia={(selectedMedia) => saveMedia && saveMedia(selectedMedia, index)}
/>
{`${errors}.entities.${index}.mainAdd..singleAdd.mediaId` && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const SingleAdd: FC<HeroMediaEntityInterface> = ({
<SingleMediaViewAndSelect
link={singleLink?.[index]}
aspectRatio={['16:9']}
isDeleteAccepted={false}
saveSelectedMedia={(selectedMedia) => saveMedia && saveMedia(selectedMedia, index)}
/>
{`${errors}.entities.${index}.singleAdd.mediaId` && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const MediaView: FC<MediaViewInterface> = ({
}
isEditMode={isEditMode}
isAddingProduct={isAddingProduct}
isDeleteAccepted={false}
aspectRatio={['4:5']}
hideVideos={true}
saveSelectedMedia={uploadThumbnailInProduct}
Expand Down Expand Up @@ -120,6 +121,7 @@ export const MediaView: FC<MediaViewInterface> = ({
<MediaSelectorLayout
label='select media'
aspectRatio={['3:4']}
isDeleteAccepted={false}
allowMultiple={true}
saveSelectedMedia={uploadMediasInProduct}
/>
Expand Down
4 changes: 4 additions & 0 deletions src/features/interfaces/mediaSelectorInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ export interface MediaSelectorLayoutProps {
allowMultiple: boolean;
aspectRatio?: string[];
hideVideos?: boolean;
isDeleteAccepted?: boolean;
saveSelectedMedia: (newSelectedMedia: common_MediaFull[]) => void;
}

export interface MediaSelectorModalProps {
allowMultiple: boolean;
aspectRatio?: string[];
hideVideos?: boolean;
isDeleteAccepted?: boolean;
closeMediaSelector: () => void;
saveSelectedMedia: (newSelectedMedia: common_MediaFull[]) => void;
}
Expand All @@ -24,6 +26,7 @@ export interface MediaSelectorInterface {
enableModal?: boolean
aspectRatio?: string[]
hideVideos?: boolean
isDeleteAccepted?: boolean;
select: (imageUrl: common_MediaFull, allowMultiple: boolean) => void

}
Expand All @@ -37,6 +40,7 @@ export interface MediaSelectorMediaListProps {
croppedImage: string | null
aspectRatio?: string[]
hideVideos?: boolean
isDeleteAccepted?: boolean;
setCroppedImage: (img: string | null) => void
select: (imageUrl: common_MediaFull, allowMultiple: boolean) => void;
setMedia: React.Dispatch<React.SetStateAction<common_MediaFull[]>>;
Expand Down
7 changes: 4 additions & 3 deletions src/features/mediaSelector/listMedia.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ export const MediaList: FC<MediaSelectorMediaListProps> = ({
selectedMedia,
enableModal = false,
croppedImage,
aspectRatio,
hideVideos = false,
isDeleteAccepted = true,
setCroppedImage,
select,
setMedia,
sortedAndFilteredMedia,
handleUploadMedia,
aspectRatio,
hideVideos = false,
}) => {
const { isSnackBarOpen, snackBarMessage, snackBarSeverity, showMessage, closeSnackBar } =
useMediaSelector();
Expand Down Expand Up @@ -190,7 +191,7 @@ export const MediaList: FC<MediaSelectorMediaListProps> = ({
/>
)}
</InputLabel>
{hoveredMediaId === media.id && (
{hoveredMediaId === media.id && isDeleteAccepted && (
<IconButton
size='small'
onClick={(e) => handleDeleteFile(media.id, e)}
Expand Down
2 changes: 2 additions & 0 deletions src/features/mediaSelector/mediaSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const MediaSelector: FC<MediaSelectorInterface> = ({
enableModal,
aspectRatio,
hideVideos,
isDeleteAccepted,
select,
}) => {
const {
Expand Down Expand Up @@ -113,6 +114,7 @@ export const MediaSelector: FC<MediaSelectorInterface> = ({
croppedImage={croppedImage}
aspectRatio={aspectRatio}
hideVideos={hideVideos}
isDeleteAccepted={isDeleteAccepted}
setCroppedImage={setCroppedImage}
select={select}
setMedia={setMedia}
Expand Down
2 changes: 2 additions & 0 deletions src/features/mediaSelector/mediaSelectorLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const MediaSelectorLayout: FC<MediaSelectorLayoutProps> = ({
allowMultiple,
aspectRatio,
hideVideos,
isDeleteAccepted,
saveSelectedMedia,
}) => {
const [mediaSelectorVisibility, setMediaSelectorVisibility] = useState(false);
Expand All @@ -28,6 +29,7 @@ export const MediaSelectorLayout: FC<MediaSelectorLayoutProps> = ({
aspectRatio={aspectRatio}
hideVideos={hideVideos}
allowMultiple={allowMultiple}
isDeleteAccepted={isDeleteAccepted}
saveSelectedMedia={saveSelectedMedia}
closeMediaSelector={handleMediaSelectorVisibility}
/>
Expand Down
2 changes: 2 additions & 0 deletions src/features/mediaSelector/mediaSelectorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const MediaSelectorModal: FC<MediaSelectorModalProps> = ({
allowMultiple,
aspectRatio,
hideVideos,
isDeleteAccepted,
closeMediaSelector,
saveSelectedMedia,
}) => {
Expand Down Expand Up @@ -64,6 +65,7 @@ export const MediaSelectorModal: FC<MediaSelectorModalProps> = ({
allowMultiple={allowMultiple}
aspectRatio={aspectRatio}
hideVideos={hideVideos}
isDeleteAccepted={isDeleteAccepted}
selectedMedia={selectedMedia}
select={select}
/>
Expand Down

0 comments on commit a08dae1

Please sign in to comment.