import { Button, Checkbox, Col, Input, Progress, Radio, Row, Select, Tooltip, Upload, notification } from "antd"; import { MoodReadResponse, PostCreateRequest, PostReadResponse, UserReadPrivateResponse, } from "@newstackdev/iosdk-newgraph-client-js"; import { NLView } from "../../../types"; import { PicturesWall } from "../../../Components/PicturesWall"; import { useActions, useAppState, useEffects } from "../../../overmind"; import { useCallback, useEffect, useRef, useState } from "react"; import { useHistory } from "react-router-dom"; import Form from "antd/lib/form"; import get from "lodash/get"; import isEmpty from "lodash/isEmpty"; import { MoodWidget } from "../../../Components/MoodWidget"; import { AddButton } from "../../../Components/Icons/AddButton"; import { AddFolder } from "../../../Components/Icons/AddFolder"; import { ContentImage } from "../../../Components/Image"; import { ContentLayout } from "../../../Components/ContentLayout"; import { CrossCircle } from "../../../Components/Icons/CrossCircle"; import { ExitButton } from "../../../Components/Icons/ExitButton"; import { IndeterminateProgress } from "../../../Components/IndeterminateProgress"; import { Info } from "../../../Components/Icons/Info"; import { LICENSES } from "../../../constants"; import { LargeArrowBack } from "../../../Components/Icons/LargeArrowBack"; import { MoodCreateModal } from "../../Mood/MoodCreate"; import { MoodsGrid } from "../../Mood/MoodsGrid"; import { NFTIcon } from "../../../Components/Icons/NTFIcon"; import { NFTLargeIcon } from "../../../Components/Icons/NFTLargeIcon"; import { ProgressButton } from "../../../Components/ProgressButton"; import { RowCheckbox } from "../../../Components/RowCheckbox"; import { SelectMood } from "../../../Components/SelectMood"; import { useEmbed } from "../../../hooks/useEmbed"; import { useForm } from "antd/lib/form/Form"; import Avatar from "antd/lib/avatar/avatar"; import Modal from "antd/lib/modal/Modal"; import PostCreateHeader from "./PostCreateHeader"; import PostCreateInfo, { LicenseProps } from "./PostCreateInfo"; import Switch from "react-switch"; import TextArea from "antd/lib/input/TextArea"; const initialLicense = { name: LICENSES[0][0], value: LICENSES[0][1] }; const mintNTFcolor = { white: "#FCFCF3", purple: "#c46ef7", green: "#b3ff00", default: "#888888", }; export const PostCreate: NLView = (props) => { const state = useAppState(); const actions = useActions(); const effects = useEffects(); const [form] = useForm(); const [mintConfirmationOpen, setMintConfirmationOpen] = useState(false); const [selectedLicense, setSelectedLicense] = useState({ name: LICENSES[0][0], value: LICENSES[0][1], }); const [isLicense, setIsLicense] = useState(false); const [errMsg, setErrMsg] = useState(""); const [moodMode, setMoodMode] = useState(false); const [contentType, setContentType] = useState(""); const [mintNFTswitch, setMintNFTswitch] = useState(false); const [embedSwitch, setEmbedSwitch] = useState(true); const [isEmbedBtnVisible, setIsEmbedBtnVisible] = useState(false); const [content, setContent] = useState(""); const user: UserReadPrivateResponse | null = state.api.auth.user; // balance check // const balances = state.newcoin.account?.acc_balances || []; const mainPoolBalances = state.newcoin?.mainPool?.acc_balances || []; const blnc = mainPoolBalances[0]?.replace(/ GNCO/, "") || 0; // || "")?.replace(/ GNCO/, "") || 0; const ncoBalance = Number(blnc); //(balances[0] || "").replace(/ NCO$/, "")) || 0; // const [moods, setMoods] = useState([]); const [post, setPost] = useState({}); const { isLoading, error, embedContent } = useEmbed(content, "200", "350"); const moods = state.api.auth.moods || []; actions.routing.setTitle("Create Post"); useEffect(() => { actions.routing.setBreadcrumbs([{ text: "post" }, { text: "create" }]); }, []); useEffect(() => { if (contentType === "text/plain" && !isLoading && !isEmpty(embedContent) && isEmpty(error)) { setIsEmbedBtnVisible(true); setEmbedSwitch(true); } else { setIsEmbedBtnVisible(false); setEmbedSwitch(false); } }, [contentType, error, isLoading, embedContent, content]); const onFinish = async (values: PostCreateRequest & { file: FileList }) => { console.log("Success:", values); if (mintNFTswitch && !mintConfirmationOpen) return setMintConfirmationOpen(true); !mintNFTswitch && setMoodMode(true); try { if (!contentType) { const f = values.file[0]; // const contentType = mime.lookup(extname(f.)); if (!f.type) { return effects.ux.message.warning("Unrecognized/unsupported content type. Upload something else."); } } const postForm = { ...values, contentType, doMint: mintNFTswitch ? "true" : "", embed: embedSwitch && isEmbedBtnVisible ? "true" : "", license: selectedLicense.value, }; const p = await actions.api.post.create({ postForm }); if (!p) return; !mintNFTswitch && setMoodMode(true); const whereToGo: PostReadResponse = p.find((p) => typeof p != "string") as any; if (!whereToGo) { return actions.ux.showNotification({ message: "All upload items failed" }); } setPost(whereToGo); } catch (ex) { setErrMsg(get(ex, "error.errorMessage.details") || get(ex, "message") || "unknown error"); } }; const onNextMode = () => { setMintConfirmationOpen(false); setMoodMode(true); }; const onChangeContentHandler = useCallback( (e: React.ChangeEvent) => { if (contentType === "text/plain") { setContent(e.currentTarget.value); if (isEmpty(e.currentTarget.value)) { setEmbedSwitch(false); } } }, [contentType], ); const onFinishFailed = (errorInfo: any) => { console.log("Failed:", errorInfo); }; const gtfooh = (v: { moods: MoodReadResponse[] }) => { actions.api.post.attachToMoods({ moods: v.moods, post }); actions.routing.historyPush({ location: `/post/${post.id}` }); setMoodMode(false); }; return (
setMintConfirmationOpen(false)} onCancel={() => { setMintConfirmationOpen(false); setPost({}); }} footer={ isEmpty(post) ? ( { form.submit(); }} className={`nl-button-primary ${!selectedLicense ? "disabled-submit-button" : ""}`} disabled={!selectedLicense || ncoBalance === 0 ? true : false} >

Mint

) : ( ) } //@ts-ignore // getContainer={() => // document.getElementById("basic") // } className="nl-white-box-modal" closeIcon={} > } className="avatar-image-top-creators" />

testnet NFT

{user?.username}

{isEmpty(post) ? ( <>

Ready to mint!

You're about to mint your NFT on Newcoin Protocol Testnet. On Testnet your NFT is not financially tradeable.

When the Mainnet goes live, your Testnet NFT will be deleted and you will be able to create tradeable NFTs!

) : ( <>

Your NFT is minting

Your mint on Newcoin Protocol Testnet is in progress. On Testnet your NFT is not financially tradeable.

When the Mainnet goes live, your Testnet NFT will be deleted and you will be able to create tradeable NFTs!

)}
); };