Skip to content

Commit

Permalink
Now modal closes after uploading, still doesn't refresh the page afte…
Browse files Browse the repository at this point in the history
…rwards
  • Loading branch information
luloxi committed Sep 28, 2024
1 parent e38f48b commit 677378e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
8 changes: 7 additions & 1 deletion packages/nextjs/app/create/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import generateTokenURI from "./_components/generateTokenURI";

// import type { NextPage } from "next";

const Create = () => {
const Create = ({ onClose }: { onClose: any }) => {
const [description, setDescription] = useState("");
const [yourJSON, setYourJSON] = useState<object>({});
const [uploadedImageIpfsPath, setUploadedImageIpfsPath] = useState(""); // NEW: For image IPFS path
Expand All @@ -19,6 +19,11 @@ const Create = () => {
setDescription("");
};

const handlePostCreated = () => {
resetForm();
onClose();
};

useEffect(() => {
const generateTokenURIString = () => {
const fullImageUrl = `https://ipfs.io/ipfs/${uploadedImageIpfsPath}`;
Expand Down Expand Up @@ -57,6 +62,7 @@ const Create = () => {
image={uploadedImageIpfsPath} // Pass the uploaded image IPFS path to MintingForm
yourJSON={yourJSON}
resetForm={resetForm}
onPostCreated={handlePostCreated}
/>
</div>
</div>
Expand Down
8 changes: 5 additions & 3 deletions packages/nextjs/app/create/_components/MintingButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ interface MintingFormProps {
image: string;
yourJSON: object;
resetForm: () => void;
onPostCreated: () => void;
}

export const MintingButtons: React.FC<MintingFormProps> = ({ yourJSON, resetForm }) => {
export const MintingButtons: React.FC<MintingFormProps> = ({ yourJSON, resetForm, onPostCreated }) => {
const { address: connectedAddress } = useAccount();
const { writeContractAsync } = useScaffoldWriteContract("PunkPosts");

Expand All @@ -32,7 +33,7 @@ export const MintingButtons: React.FC<MintingFormProps> = ({ yourJSON, resetForm
}
};

const handlePaidMint = async () => {
const handleCreatePost = async () => {
if (!connectedAddress) {
notification.error("Please connect your wallet");
return;
Expand All @@ -52,6 +53,7 @@ export const MintingButtons: React.FC<MintingFormProps> = ({ yourJSON, resetForm
notification.success("Posted successfully!");
}
resetForm();
onPostCreated();
} catch (error) {
console.error("Error during posting:", error);
notification.error("Posting failed, please try again.");
Expand All @@ -63,7 +65,7 @@ export const MintingButtons: React.FC<MintingFormProps> = ({ yourJSON, resetForm
return (
<div className="flex flex-col justify-center items-center mt-6 gap-3">
<div className="flex items-center">
<button className="cool-button" disabled={loading} onClick={handlePaidMint}>
<button className="cool-button" disabled={loading} onClick={handleCreatePost}>
Create Post
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/app/explore/Explore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const Explore = () => {
<div className="flex justify-center">{!isConnected || isConnecting ? <RainbowKitCustomConnectButton /> : ""}</div>
{listedCollectibles.length === 0 ? (
<div className="flex justify-center items-center mt-10">
<div className="text-2xl text-primary-content">No NFTs found</div>
<div className="text-2xl text-primary-content">No posts found</div>
</div>
) : loading ? (
<LoadingSpinner />
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/app/profile/[address]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ const ProfilePage: NextPage = () => {

{listedCollectibles.length === 0 ? (
<div className="flex justify-center items-center mt-10">
<div className="text-2xl text-primary-content">No NFTs found</div>
<div className="text-2xl text-primary-content">No posts found</div>
</div>
) : loading ? (
<LoadingSpinner />
Expand Down
8 changes: 5 additions & 3 deletions packages/nextjs/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ export const Footer = () => {
<PlusIcon className="h-10 w-10" />
</div>

<Modal isOpen={isModalOpen} onClose={closeModal}>
<Create />
</Modal>
{isModalOpen && (
<Modal isOpen={isModalOpen} onClose={closeModal}>
<Create onClose={closeModal} />
</Modal>
)}
<div className="min-h-0 py-5 px-1 lg:mb-0">
<div className="w-full">
<ul className="menu menu-horizontal w-full">
Expand Down

0 comments on commit 677378e

Please sign in to comment.