Skip to content

Commit

Permalink
feat: small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
josetano2 committed Aug 22, 2024
1 parent 42a7f91 commit 03c05df
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 48 deletions.
52 changes: 21 additions & 31 deletions src/config/cloudinary.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
import { Cloudinary } from "@cloudinary/url-gen";

export const cld = new Cloudinary({ cloud: { cloudName: "djg4ybxvx" } });
export const cld = new Cloudinary({ cloud: { cloudName: "dau03r7yn" } });

export async function uploadImage(file, onLoading) {
onLoading(true);
const formData = new FormData();
formData.append("file", file);
formData.append("upload_preset", "c9digoqw");

// const response = await fetch(
// `https://api.cloudinary.com/v1_1/djg4ybxvx/image/upload`,
// {
// method: "POST",
// body: formData,
// }
// );
export async function uploadImage({ file, onLoading }) {
onLoading(true);
const formData = new FormData();
formData.append("file", file);
formData.append("upload_preset", "cdlo4fjr");

// if (response.ok) {
// const data = await response.json();
// onLoading(false);
// return data.secure_url;
// } else {
// onLoading(false);
// throw new Error("Upload failed");
// }
try {
const response = await axios.post(
`https://api.cloudinary.com/v1_1/djg4ybxvx/image/upload`, // replace with your cloud_name
formData
);
console.log(response.data);
return response.data.secure_url;
} catch (error) {
console.error(error);
const response = await fetch(
`https://api.cloudinary.com/v1_1/dau03r7yn/image/upload`,
{
method: "POST",
body: formData,
}
);

if (response.ok) {
const data = await response.json();
onLoading(false);
return data.secure_url;
} else {
onLoading(false);
throw new Error("Upload failed");
}
}
24 changes: 19 additions & 5 deletions src/ss_frontend/src/components/ProfileSidebar.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import React from "react";
import React, { useEffect } from "react";
import { AiOutlineUser } from "react-icons/ai";
import { Link } from "react-router-dom";
import { Link, useNavigate } from "react-router-dom";
import { useAuth } from "../hooks/UseAuth";
import { useQuery } from "@tanstack/react-query";

const ProfileSidebar = () => {
const { isAuthenticated, getUser, user } = useAuth();
const navigate = useNavigate();

return (
<>
<div className=" border-gray-200 border rounded-xl flex-col flex max-w-md items-center w-full">
Expand All @@ -11,9 +16,18 @@ const ProfileSidebar = () => {
</div>
<p className="text-2xl pt-8">You haven't logged in yet</p>
<div className="mt-4 mb-4 pr-8 pl-8">
<Link to="/profile" className="btn btn-wide btn-outline btn-primary">
Login using internet identity
</Link>
{isAuthenticated ? (
<>
<div>tes</div>
</>
) : (
<Link
to="/profile"
className="btn btn-wide btn-outline btn-primary"
>
Login using internet identity
</Link>
)}
</div>
</div>
</>
Expand Down
6 changes: 4 additions & 2 deletions src/ss_frontend/src/pages/ProfileDetailPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ export default function ProfileDetailPage() {
if (!isLoading) {
if (data.ok) {
setUsername(data.ok.username);
} else {
navigate(`/profile-form`);
}
}
}, [data, isLoading]);

// masukin post
return <div>{username}</div>;
return <div className="p-32">{username}</div>;
}
10 changes: 0 additions & 10 deletions src/ss_frontend/src/pages/ProfilePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ export default function ProfilePage() {
queryFn: getUser,
});

useEffect(() => {
if (!isLoading) {
if (data.ok) {
navigate(`/profile`);
} else {
navigate(`/profile-form`);
}
}
}, [data, isLoading]);

return (
<>
<MainTemplate>
Expand Down

0 comments on commit 03c05df

Please sign in to comment.