Skip to content

Commit

Permalink
ios support for heic images added
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahan-nub committed Oct 24, 2024
1 parent 9a89c89 commit b048593
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@reduxjs/toolkit": "^2.2.1",
"emoji-picker-react": "^4.12.0",
"firebase": "^10.8.1",
"heic2any": "^0.0.4",
"next": "14.1.3",
"react": "^18",
"react-dom": "^18",
Expand Down
20 changes: 14 additions & 6 deletions src/components/Chat/ChatInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { selectMenu } from "@/lib/features/menuSlice";
import { ref, uploadBytes, getDownloadURL } from "firebase/storage";
import { TbLoader2 } from "react-icons/tb";
import dynamic from "next/dynamic";
import heic2any from "heic2any";



const Picker = dynamic(
Expand Down Expand Up @@ -77,9 +79,14 @@ export default function ChatInput({ handleMessageUpdate }) {
setFileLoading(true);
const file = event.target.files?.[0];
if (file) {
setImage(file);
console.log(file);
// handleUpload();
if (file.name.includes(".heic") || file.name.includes(".HEIC")) {
alert("heic file type is not supported on web, please use a different format.")
const convertedImage = await heic2any({ blob: file, toType: "image/jpeg" });
setImage(convertedImage);
} else {
setImage(file);
console.log(file);
}
setFileLoading(false);
}
};
Expand All @@ -88,6 +95,7 @@ export default function ChatInput({ handleMessageUpdate }) {
const uploadImage = async () => {
if (image) {
setIsUploading(true);

const storageRef = ref(storage, `images/${image.name}`);
try {
const snapshot = await uploadBytes(storageRef, image);
Expand Down Expand Up @@ -131,7 +139,7 @@ export default function ChatInput({ handleMessageUpdate }) {
setImage(null);
setImageUrl(null);
}
}, 3000);
}, 2000);
} catch (error) {
console.error("Error uploading image:", error);
}
Expand Down Expand Up @@ -201,7 +209,7 @@ export default function ChatInput({ handleMessageUpdate }) {
)}
{isUploading && (
<p className="text-4xl text-white font-bold z-10 scale-110 transition-all duration-500 bg-color-1 rounded-md shadow-lg border-color-3 flex items-center justify-center w-max py-6 px-4">
Loading Image&nbsp;
{/* Loading Image&nbsp; */}
<TbLoader2 className="animate-spin"></TbLoader2>
</p>
)}
Expand All @@ -212,7 +220,7 @@ export default function ChatInput({ handleMessageUpdate }) {
onClick={handleUpload}
className={` mx-1 md:mx-2 text-base lg:text-lg cursor-pointer ${
imageUrl
? "text-blue-400 scale-105 "
? "text-blue-400 scale-105 animate-bounce font-bold"
: "text-slate-200 hover:text-white"
}`}
></FaFileUpload>
Expand Down

0 comments on commit b048593

Please sign in to comment.