From 0e04daebfbd9cccecce45a4c9357bc78235574fb Mon Sep 17 00:00:00 2001 From: ekzyis Date: Tue, 5 Dec 2023 01:43:40 +0100 Subject: [PATCH] Return full context in useMe Ran search and replace: s/const me = useMe()/const { me } = useMe()/ s/const refreshMe = useMeRefresh()/const { refreshMe } = useMe()/ + removed import of `useMeRefresh` manually --- components/adv-post-form.js | 2 +- components/banners.js | 2 +- components/bounty-form.js | 2 +- components/comment.js | 2 +- components/discussion-form.js | 2 +- components/fee-button.js | 2 +- components/header.js | 6 +++--- components/hidden-wallet-summary.js | 2 +- components/image.js | 2 +- components/invoice.js | 2 +- components/item-act.js | 2 +- components/item-full.js | 2 +- components/item-info.js | 2 +- components/link-form.js | 2 +- components/logger.js | 2 +- components/me.js | 10 ++-------- components/pay-bounty.js | 2 +- components/poll-form.js | 2 +- components/poll.js | 2 +- components/post.js | 2 +- components/price.js | 2 +- components/reply.js | 2 +- components/share.js | 4 ++-- components/switch-account.js | 10 +++++----- components/upvote.js | 4 ++-- components/user-header.js | 4 ++-- pages/[name]/index.js | 2 +- pages/referrals/[when].js | 2 +- pages/settings.js | 2 +- pages/wallet.js | 8 ++++---- pages/withdrawals/[id].js | 2 +- 31 files changed, 44 insertions(+), 50 deletions(-) diff --git a/components/adv-post-form.js b/components/adv-post-form.js index 849dc1ac..56ec4d0f 100644 --- a/components/adv-post-form.js +++ b/components/adv-post-form.js @@ -20,7 +20,7 @@ export function AdvPostInitial ({ forward, boost }) { } export default function AdvPostForm ({ children }) { - const me = useMe() + const { me } = useMe() const router = useRouter() const { merge } = useFeeButton() diff --git a/components/banners.js b/components/banners.js index 79f0f039..df7e7733 100644 --- a/components/banners.js +++ b/components/banners.js @@ -9,7 +9,7 @@ import { BALANCE_LIMIT_MSATS } from '../lib/constants' import { msatsToSats, numWithUnits } from '../lib/format' export function WelcomeBanner () { - const me = useMe() + const { me } = useMe() const toaster = useToast() const [hidden, setHidden] = useState(true) const handleClose = async () => { diff --git a/components/bounty-form.js b/components/bounty-form.js index ce629af1..c76fdac8 100644 --- a/components/bounty-form.js +++ b/components/bounty-form.js @@ -25,7 +25,7 @@ export function BountyForm ({ }) { const router = useRouter() const client = useApolloClient() - const me = useMe() + const { me } = useMe() const toaster = useToast() const schema = bountySchema({ client, me, existingBoost: item?.boost }) const [upsertBounty] = useMutation( diff --git a/components/comment.js b/components/comment.js index 2f064c8c..32e00abe 100644 --- a/components/comment.js +++ b/components/comment.js @@ -100,7 +100,7 @@ export default function Comment ({ rootText, noComments, noReply, truncate, depth }) { const [edit, setEdit] = useState() - const me = useMe() + const { me } = useMe() const isHiddenFreebie = !me?.privates?.wildWestMode && !me?.privates?.greeterMode && !item.mine && item.freebie && !item.freedFreebie const [collapse, setCollapse] = useState( (isHiddenFreebie || item?.user?.meMute || (item?.outlawed && !me?.privates?.wildWestMode)) && !includeParent diff --git a/components/discussion-form.js b/components/discussion-form.js index 3aaa4b2c..62ef9cb7 100644 --- a/components/discussion-form.js +++ b/components/discussion-form.js @@ -24,7 +24,7 @@ export function DiscussionForm ({ }) { const router = useRouter() const client = useApolloClient() - const me = useMe() + const { me } = useMe() const schema = discussionSchema({ client, me, existingBoost: item?.boost }) // if Web Share Target API was used const shareTitle = router.query.title diff --git a/components/fee-button.js b/components/fee-button.js index 502724da..c354f53d 100644 --- a/components/fee-button.js +++ b/components/fee-button.js @@ -110,7 +110,7 @@ function FreebieDialog () { } export default function FeeButton ({ ChildButton = SubmitButton, variant, text, disabled }) { - const me = useMe() + const { me } = useMe() const { lines, total, disabled: ctxDisabled } = useFeeButton() // freebies: there's only a base cost and we don't have enough sats const free = total === lines.baseCost?.modifier(0) && lines.baseCost?.allowFreebies && me?.privates?.sats < total diff --git a/components/header.js b/components/header.js index b3e81a92..a6460bdf 100644 --- a/components/header.js +++ b/components/header.js @@ -159,7 +159,7 @@ function NavProfileMenu ({ me, dropNavKey }) { } function StackerCorner ({ dropNavKey }) { - const me = useMe() + const { me } = useMe() const walletLimitReached = me.privates?.sats >= msatsToSats(BALANCE_LIMIT_MSATS) @@ -276,7 +276,7 @@ function NavItems ({ className, sub, prefix }) { } function PostItem ({ className, prefix }) { - const me = useMe() + const { me } = useMe() if (me) { return ( @@ -302,7 +302,7 @@ export default function Header ({ sub }) { const prefix = sub ? `/~${sub}` : '' const topNavKey = path.split('/')[sub ? 2 : 1] ?? '' const dropNavKey = path.split('/').slice(sub ? 2 : 1).join('/') - const me = useMe() + const { me } = useMe() return ( diff --git a/components/hidden-wallet-summary.js b/components/hidden-wallet-summary.js index 161f03b3..c1d71253 100644 --- a/components/hidden-wallet-summary.js +++ b/components/hidden-wallet-summary.js @@ -3,7 +3,7 @@ import { abbrNum, numWithUnits } from '../lib/format' import { useMe } from './me' export default function HiddenWalletSummary ({ abbreviate, fixedWidth }) { - const me = useMe() + const { me } = useMe() const [hover, setHover] = useState(false) // prevent layout shifts when hovering by fixing width to initial rendered width diff --git a/components/image.js b/components/image.js index aa847802..0171cc1a 100644 --- a/components/image.js +++ b/components/image.js @@ -20,7 +20,7 @@ export function decodeOriginalUrl (imgproxyUrl) { } function ImageOriginal ({ src, topLevel, nofollow, tab, children, onClick, ...props }) { - const me = useMe() + const { me } = useMe() const [showImage, setShowImage] = useState(false) useEffect(() => { diff --git a/components/invoice.js b/components/invoice.js index 76c46a14..820d5dbd 100644 --- a/components/invoice.js +++ b/components/invoice.js @@ -159,7 +159,7 @@ const defaultOptions = { // there's lots of state cascading paired with logic // independent of the state, and it's hard to follow export const useInvoiceable = (onSubmit, options = defaultOptions) => { - const me = useMe() + const { me } = useMe() const [createInvoice, { data }] = useMutation(gql` mutation createInvoice($amount: Int!) { createInvoice(amount: $amount, hodlInvoice: true, expireSecs: 180) { diff --git a/components/item-act.js b/components/item-act.js index dfe1adc3..1c5d94fc 100644 --- a/components/item-act.js +++ b/components/item-act.js @@ -42,7 +42,7 @@ const addCustomTip = (amount) => { export default function ItemAct ({ onClose, itemId, down, children }) { const inputRef = useRef(null) - const me = useMe() + const { me } = useMe() const [oValue, setOValue] = useState() const strike = useLightning() diff --git a/components/item-full.js b/components/item-full.js index e1db26d5..39277774 100644 --- a/components/item-full.js +++ b/components/item-full.js @@ -28,7 +28,7 @@ import { numWithUnits } from '../lib/format' import { useQuoteReply } from './use-quote-reply' function BioItem ({ item, handleClick }) { - const me = useMe() + const { me } = useMe() if (!item.text) { return null } diff --git a/components/item-info.js b/components/item-info.js index 4033f5b7..3da648dc 100644 --- a/components/item-info.js +++ b/components/item-info.js @@ -28,7 +28,7 @@ export default function ItemInfo ({ onQuoteReply, nofollow, extraBadges, nested }) { const editThreshold = new Date(item.createdAt).getTime() + 10 * 60000 - const me = useMe() + const { me } = useMe() const router = useRouter() const [canEdit, setCanEdit] = useState(item.mine && (Date.now() < editThreshold)) diff --git a/components/link-form.js b/components/link-form.js index e2eed965..ef4b46b8 100644 --- a/components/link-form.js +++ b/components/link-form.js @@ -19,7 +19,7 @@ import { ItemButtonBar } from './post' export function LinkForm ({ item, sub, editThreshold, children }) { const router = useRouter() const client = useApolloClient() - const me = useMe() + const { me } = useMe() const toaster = useToast() const schema = linkSchema({ client, me, existingBoost: item?.boost }) // if Web Share Target API was used diff --git a/components/logger.js b/components/logger.js index 64d331b7..14a7c6b6 100644 --- a/components/logger.js +++ b/components/logger.js @@ -39,7 +39,7 @@ export function detectOS () { export const LoggerContext = createContext() export function LoggerProvider ({ children }) { - const me = useMe() + const { me } = useMe() const [name, setName] = useState() const [os, setOS] = useState() diff --git a/components/me.js b/components/me.js index 99cc6a48..b9a785f7 100644 --- a/components/me.js +++ b/components/me.js @@ -15,18 +15,12 @@ export function MeProvider ({ me, children }) { const futureMe = data?.me ?? (data?.me === null ? null : me) return ( - + {children} ) } export function useMe () { - const { me } = useContext(MeContext) - return me -} - -export function useMeRefresh () { - const { refetch } = useContext(MeContext) - return refetch + return useContext(MeContext) } diff --git a/components/pay-bounty.js b/components/pay-bounty.js index 483de2df..5c284d2b 100644 --- a/components/pay-bounty.js +++ b/components/pay-bounty.js @@ -10,7 +10,7 @@ import { payOrLoginError, useInvoiceModal } from './invoice' import { useAct } from './item-act' export default function PayBounty ({ children, item }) { - const me = useMe() + const { me } = useMe() const showModal = useShowModal() const root = useRoot() diff --git a/components/poll-form.js b/components/poll-form.js index 817a7da3..33ff42ad 100644 --- a/components/poll-form.js +++ b/components/poll-form.js @@ -15,7 +15,7 @@ import { ItemButtonBar } from './post' export function PollForm ({ item, sub, editThreshold, children }) { const router = useRouter() const client = useApolloClient() - const me = useMe() + const { me } = useMe() const toaster = useToast() const schema = pollSchema({ client, me, existingBoost: item?.boost }) diff --git a/components/poll.js b/components/poll.js index 987f96ee..4c63d8d4 100644 --- a/components/poll.js +++ b/components/poll.js @@ -11,7 +11,7 @@ import { POLL_COST } from '../lib/constants' import { payOrLoginError, useInvoiceModal } from './invoice' export default function Poll ({ item }) { - const me = useMe() + const { me } = useMe() const [pollVote] = useMutation( gql` mutation pollVote($id: ID!, $hash: String, $hmac: String) { diff --git a/components/post.js b/components/post.js index a98d1574..1b32bfbc 100644 --- a/components/post.js +++ b/components/post.js @@ -16,7 +16,7 @@ import Delete from './delete' import CancelButton from './cancel-button' export function PostForm ({ type, sub, children }) { - const me = useMe() + const { me } = useMe() const [errorMessage, setErrorMessage] = useState() const prefix = sub?.name ? `/~${sub.name}` : '' diff --git a/components/price.js b/components/price.js index f9fa6f2f..9ca63f6c 100644 --- a/components/price.js +++ b/components/price.js @@ -18,7 +18,7 @@ export function usePrice () { } export function PriceProvider ({ price, children }) { - const me = useMe() + const { me } = useMe() const fiatCurrency = me?.privates?.fiatCurrency const { data } = useQuery(PRICE, { variables: { fiatCurrency }, diff --git a/components/reply.js b/components/reply.js index 055f03d0..e5d53845 100644 --- a/components/reply.js +++ b/components/reply.js @@ -34,7 +34,7 @@ export function ReplyOnAnotherPage ({ item }) { export default forwardRef(function Reply ({ item, onSuccess, replyOpen, children, placeholder, onQuoteReply, onCancelQuote, quote }, ref) { const [reply, setReply] = useState(replyOpen || quote) - const me = useMe() + const { me } = useMe() const parentId = item.id const replyInput = useRef(null) const toaster = useToast() diff --git a/components/share.js b/components/share.js index c43e4145..4c51d3ba 100644 --- a/components/share.js +++ b/components/share.js @@ -17,7 +17,7 @@ const referrurl = (ipath, me) => { } export default function Share ({ path, title, className = '' }) { - const me = useMe() + const { me } = useMe() const toaster = useToast() const url = referrurl(path, me) @@ -65,7 +65,7 @@ export default function Share ({ path, title, className = '' }) { } export function CopyLinkDropdownItem ({ item }) { - const me = useMe() + const { me } = useMe() const toaster = useToast() const url = referrurl(`/items/${item.id}`, me) return ( diff --git a/components/switch-account.js b/components/switch-account.js index 16260ade..eb2afbe9 100644 --- a/components/switch-account.js +++ b/components/switch-account.js @@ -2,7 +2,7 @@ import { createContext, useCallback, useContext, useEffect, useState } from 'rea import AnonIcon from '../svgs/spy-fill.svg' import { useRouter } from 'next/router' import cookie from 'cookie' -import { useMe, useMeRefresh } from './me' +import { useMe } from './me' import Image from 'react-bootstrap/Image' import Link from 'next/link' import { SSR } from '../lib/constants' @@ -14,7 +14,7 @@ const AccountContext = createContext() const b64Decode = str => Buffer.from(str, 'base64').toString('utf-8') export const AccountProvider = ({ children }) => { - const me = useMe() + const { me } = useMe() const [accounts, setAccounts] = useState([]) const [isAnon, setIsAnon] = useState(true) @@ -64,7 +64,7 @@ export const useAccounts = () => useContext(AccountContext) const AnonAccount = ({ selected, onClick }) => { const { isAnon, setIsAnon } = useAccounts() - const refreshMe = useMeRefresh() + const { refreshMe } = useMe() return (
{ } const Account = ({ account, className }) => { - const me = useMe() + const { me } = useMe() const [name, setName] = useState(account.name) const [src, setSrc] = useState(account.photoId || '/dorian400.jpg') - const refreshMe = useMeRefresh() + const { refreshMe } = useMe() const { setIsAnon } = useAccounts() useQuery(USER, { diff --git a/components/upvote.js b/components/upvote.js index 49de8211..4e104dae 100644 --- a/components/upvote.js +++ b/components/upvote.js @@ -15,7 +15,7 @@ import { numWithUnits } from '../lib/format' import { Dropdown } from 'react-bootstrap' const UpvotePopover = ({ target, show, handleClose }) => { - const me = useMe() + const { me } = useMe() return (
@{user.name}
@@ -181,7 +181,7 @@ function HeaderNym ({ user, isMe }) { } function HeaderHeader ({ user }) { - const me = useMe() + const { me } = useMe() const showModal = useShowModal() const toaster = useToast() diff --git a/pages/[name]/index.js b/pages/[name]/index.js index 6c267a0e..7b6c687e 100644 --- a/pages/[name]/index.js +++ b/pages/[name]/index.js @@ -88,7 +88,7 @@ export default function User ({ ssrData }) { const [create, setCreate] = useState(false) const [edit, setEdit] = useState(false) const router = useRouter() - const me = useMe() + const { me } = useMe() const { data } = useQuery(USER_FULL, { variables: { ...router.query } }) if (!data && !ssrData) return diff --git a/pages/referrals/[when].js b/pages/referrals/[when].js index 54df8126..1a1d4f88 100644 --- a/pages/referrals/[when].js +++ b/pages/referrals/[when].js @@ -36,7 +36,7 @@ export const getServerSideProps = getGetServerSideProps({ query: REFERRALS, auth export default function Referrals ({ ssrData }) { const router = useRouter() - const me = useMe() + const { me } = useMe() const select = async values => { const { when, ...query } = values diff --git a/pages/settings.js b/pages/settings.js index 8dec7ba8..57bb790b 100644 --- a/pages/settings.js +++ b/pages/settings.js @@ -35,7 +35,7 @@ function bech32encode (hexString) { export default function Settings ({ ssrData }) { const toaster = useToast() - const me = useMe() + const { me } = useMe() const [setSettings] = useMutation(SET_SETTINGS, { update (cache, { data: { setSettings } }) { cache.modify({ diff --git a/pages/wallet.js b/pages/wallet.js index 52bec1bc..bb353dbf 100644 --- a/pages/wallet.js +++ b/pages/wallet.js @@ -59,7 +59,7 @@ export default function Wallet () { } function YouHaveSats () { - const me = useMe() + const { me } = useMe() const limitReached = me?.privates?.sats >= msatsToSats(BALANCE_LIMIT_MSATS) return (

@@ -97,7 +97,7 @@ export function WalletForm () { } export function FundForm () { - const me = useMe() + const { me } = useMe() const [showAlert, setShowAlert] = useState(true) const router = useRouter() const [createInvoice, { called, error }] = useMutation(gql` @@ -200,7 +200,7 @@ export function SelectedWithdrawalForm () { export function InvWithdrawal () { const router = useRouter() - const me = useMe() + const { me } = useMe() const [createWithdrawl, { called, error }] = useMutation(CREATE_WITHDRAWL) @@ -340,7 +340,7 @@ export function LnWithdrawal () { } export function LnAddrWithdrawal () { - const me = useMe() + const { me } = useMe() const router = useRouter() const [sendToLnAddr, { called, error }] = useMutation(SEND_TO_LNADDR) const defaultOptions = { min: 1 } diff --git a/pages/withdrawals/[id].js b/pages/withdrawals/[id].js index 37e2fea2..ea9a8839 100644 --- a/pages/withdrawals/[id].js +++ b/pages/withdrawals/[id].js @@ -114,7 +114,7 @@ function LoadWithdrawl () { function PrivacyOption ({ wd }) { if (!wd.bolt11) return - const me = useMe() + const { me } = useMe() const keepUntil = datePivot(new Date(wd.createdAt), { days: INVOICE_RETENTION_DAYS }) const oldEnough = new Date() >= keepUntil if (!oldEnough) {