diff --git a/frontend/src/components/SqueakCard/index.js b/frontend/src/components/SqueakCard/index.js index a65f1944..cf0cd864 100644 --- a/frontend/src/components/SqueakCard/index.js +++ b/frontend/src/components/SqueakCard/index.js @@ -11,17 +11,20 @@ import axios from 'axios' import {API_URL} from '../../config' import MakeSqueak from '../../features/squeaks/MakeSqueak' import DeleteSqueak from '../../features/squeaks/DeleteSqueak' +import BuySqueak from '../../features/squeaks/BuySqueak' import ContentEditable from 'react-contenteditable' import { setLikeSqueak, setUnlikeSqueak, + fetchSqueakOffers, } from '../../features/squeaks/squeaksSlice' const SqueakCard = React.memo(function SqueakCard(props) { const [replyModalOpen, setModalOpen] = useState(false) const [deleteModalOpen, setDeleteModalOpen] = useState(false) + const [buyModalOpen, setBuyModalOpen] = useState(false) const [parent, setParent] = useState(false) const [styleBody, setStyleBody] = useState(false) const dispatch = useDispatch() @@ -68,6 +71,16 @@ const SqueakCard = React.memo(function SqueakCard(props) { setTimeout(()=>{ setDeleteModalOpen(!deleteModalOpen) },20) } + const toggleBuyModal = (e, type) => { + if(e){ + e.preventDefault(); + e.stopPropagation(); + } + setStyleBody(!styleBody) + if(type === 'parent'){setParent(true)}else{setParent(false)} + setTimeout(()=>{ setBuyModalOpen(!buyModalOpen) },20) + } + const handleModalClick = (e) => { e.stopPropagation() @@ -139,7 +152,13 @@ const SqueakCard = React.memo(function SqueakCard(props) {
{props.squeak.getContentStr()}
: -
+
{ + e.preventDefault(); + dispatch(fetchSqueakOffers(props.id)); + toggleBuyModal(); + } + } + className="card-content-info card-content-locked-content">
Locked content @@ -237,6 +256,25 @@ const SqueakCard = React.memo(function SqueakCard(props) {
: null}
: null} + {/* buy modal */} + {props.squeak ? +
toggleBuyModal()} style={{display: buyModalOpen ? 'block' : 'none'}} className="modal-edit"> + {buyModalOpen ? +
handleModalClick(e)} className="modal-content"> +
+
+
toggleBuyModal()} className="modal-closeIcon-wrap"> + +
+
+

Buy Squeak

+
+
+ +
+
: null} +
: null} +
) diff --git a/frontend/src/features/squeaks/BuySqueak.js b/frontend/src/features/squeaks/BuySqueak.js new file mode 100644 index 00000000..f618be8b --- /dev/null +++ b/frontend/src/features/squeaks/BuySqueak.js @@ -0,0 +1,128 @@ +import React, { useEffect, useState, useContext, useRef } from 'react' +import { withRouter } from 'react-router-dom' +import { unwrapResult } from '@reduxjs/toolkit' + +import moment from 'moment' +import ContentEditable from 'react-contenteditable' +import { Link } from 'react-router-dom' +import { getProfileImageSrcString } from '../../squeakimages/images'; +import Loader from '../../components/Loader' + +import { Form, Input, Checkbox, Relevant, Debug, TextArea, Option } from 'informed'; + +import Select from 'react-select' + +import { useSelector } from 'react-redux' +import { useDispatch } from 'react-redux' + + +import { + setBuySqueak, + selectBuySqueakStatus, + selectSqueakOffers, + fetchSqueakOffers, +} from '../squeaks/squeaksSlice' +import { + fetchPaymentSummaryForSqueak, + selectPaymentSummaryForSqueak, +} from '../../features/payments/paymentsSlice' +import { + selectSigningProfiles, + fetchSigningProfiles, +} from '../../features/profiles/profilesSlice' + +const BuySqueak = (props) => { + console.log(props.squeakHash); + + const signingProfiles = useSelector(selectSigningProfiles); + const buySqueakStatus = useSelector(selectBuySqueakStatus); + const squeakOffers = useSelector(selectSqueakOffers); + const dispatch = useDispatch(); + + const [offer, setOffer] = useState(null); + + + const buySqueak = (id) => { + const offerId = offer && offer.getOfferId(); + if (!offerId) { + return; + } + const values = { + offerId: offerId, + squeakHash: props.squeakHash, + } + console.log('Buy clicked.'); + dispatch(setBuySqueak(values)) + .then(unwrapResult) + .then(() => { + dispatch(fetchPaymentSummaryForSqueak({squeakHash: props.squeakHash})); + }) + .catch((err) => { + alert(err.message); + }); + if (props.submittedCallback) { + props.submittedCallback(); + } + } + + const handleChangeOffer = (e) => { + setOffer(e.value); + } + + const optionsFromOffers = (offers) => { + console.log("optionsFromOffers"); + console.log(offers); + return offers.map((offer) => { + return { value: offer, label: `${offer.getPriceMsat() / 1000} sats (${offer.getPeerAddress().getHost()}:${offer.getPeerAddress().getPort()})` } + }); + } + + return ( + <> + + +
+
+ {squeakOffers.length} offers +
+ -
- {offer && - <> -
- Price: {offer.getPriceMsat() / 1000} sats -
-
- Peer: {offer.getPeerAddress().getHost()}:{offer.getPeerAddress().getPort()} -
-
- Lightning Node:  - - {offer.getNodePubkey()}@{offer.getNodeHost()}:{offer.getNodePort()} - -
- - } -
-
-
-
-
- Buy -
-
-
+ {squeak ? +
toggleBuyModal()} style={{display: buyModalOpen ? 'block' : 'none'}} className="modal-edit"> + {buyModalOpen ? +
handleModalClick(e)} className="modal-content"> +
+
+
toggleBuyModal()} className="modal-closeIcon-wrap"> +
- -
+

Buy Squeak

+
+
+
: null}
:null} @@ -456,29 +392,29 @@ import { ICON_ARROWBACK, ICON_HEART, ICON_REPLY, ICON_RETWEET, ICON_HEARTFULL,
{tab === 'Sent Payments' ? - <> - - + <> + + : tab === 'Received Payments' ? - <> - - - :
- Nothing to see here .. -
- Try searching for people, usernames, or keywords + <> + + + :
+ Nothing to see here .. +
+ Try searching for people, usernames, or keywords -
- } -
-
-
} + } +
+ + + } - - } + + } - export default withRouter(Squeak) + export default withRouter(Squeak)