image optimization. Image resizing client side, index added to db, pagination
This commit is contained in:
@@ -3,7 +3,7 @@ import { useParams, useNavigate } from "react-router-dom";
|
||||
import { Item, Rental, Address } from "../types";
|
||||
import { useAuth } from "../contexts/AuthContext";
|
||||
import { itemAPI, rentalAPI, addressAPI, userAPI } from "../services/api";
|
||||
import { uploadFiles, getPublicImageUrl } from "../services/uploadService";
|
||||
import { uploadImagesWithVariants, getImageUrl } from "../services/uploadService";
|
||||
import AvailabilitySettings from "../components/AvailabilitySettings";
|
||||
import ImageUpload from "../components/ImageUpload";
|
||||
import ItemInformation from "../components/ItemInformation";
|
||||
@@ -161,8 +161,8 @@ const EditItem: React.FC = () => {
|
||||
// Set existing images - store S3 keys and generate preview URLs
|
||||
if (item.imageFilenames && item.imageFilenames.length > 0) {
|
||||
setExistingImageKeys(item.imageFilenames);
|
||||
// Generate preview URLs from S3 keys
|
||||
setImagePreviews(item.imageFilenames.map((key: string) => getPublicImageUrl(key)));
|
||||
// Generate preview URLs from S3 keys (use thumbnail for previews)
|
||||
setImagePreviews(item.imageFilenames.map((key: string) => getImageUrl(key, 'thumbnail')));
|
||||
}
|
||||
|
||||
// Determine which pricing unit to select based on existing data
|
||||
@@ -315,11 +315,11 @@ const EditItem: React.FC = () => {
|
||||
}
|
||||
|
||||
try {
|
||||
// Upload new images to S3 and get their keys
|
||||
// Upload new images to S3 and get their keys (with resizing)
|
||||
let newImageKeys: string[] = [];
|
||||
if (imageFiles.length > 0) {
|
||||
const uploadResults = await uploadFiles("item", imageFiles);
|
||||
newImageKeys = uploadResults.map((result) => result.key);
|
||||
const uploadResults = await uploadImagesWithVariants("item", imageFiles);
|
||||
newImageKeys = uploadResults.map((result) => result.baseKey);
|
||||
}
|
||||
|
||||
// Combine existing S3 keys with newly uploaded keys
|
||||
|
||||
Reference in New Issue
Block a user