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
This commit is contained in:
ekzyis 2023-12-05 01:43:40 +01:00
parent 051ba7397a
commit 0e04daebfb
31 changed files with 44 additions and 50 deletions

View File

@ -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()

View File

@ -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 () => {

View File

@ -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(

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 (
<Container as='header' className='px-sm-0'>

View File

@ -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

View File

@ -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(() => {

View File

@ -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) {

View File

@ -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()

View File

@ -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
}

View File

@ -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))

View File

@ -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

View File

@ -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()

View File

@ -15,18 +15,12 @@ export function MeProvider ({ me, children }) {
const futureMe = data?.me ?? (data?.me === null ? null : me)
return (
<MeContext.Provider value={{ me: futureMe, refetch }}>
<MeContext.Provider value={{ me: futureMe, refreshMe: refetch }}>
{children}
</MeContext.Provider>
)
}
export function useMe () {
const { me } = useContext(MeContext)
return me
}
export function useMeRefresh () {
const { refetch } = useContext(MeContext)
return refetch
return useContext(MeContext)
}

View File

@ -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()

View File

@ -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 })

View File

@ -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) {

View File

@ -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}` : ''

View File

@ -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 },

View File

@ -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()

View File

@ -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 (

View File

@ -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 (
<div
className='d-flex flex-column me-2 my-1 text-center'
@ -85,10 +85,10 @@ const AnonAccount = ({ selected, onClick }) => {
}
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,
{

View File

@ -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 (
<Overlay
show={show}
@ -73,7 +73,7 @@ export default function UpVote ({ item, className }) {
const [voteShow, _setVoteShow] = useState(false)
const [tipShow, _setTipShow] = useState(false)
const ref = useRef()
const me = useMe()
const { me } = useMe()
const [setWalkthrough] = useMutation(
gql`
mutation setWalkthrough($upvotePopover: Boolean, $tipPopover: Boolean) {

View File

@ -154,7 +154,7 @@ function NymEdit ({ user, setEditting }) {
}
function NymView ({ user, isMe, setEditting }) {
const me = useMe()
const { me } = useMe()
return (
<div className='d-flex align-items-center mb-2'>
<div className={styles.username}>@{user.name}<Hat className='' user={user} badge /></div>
@ -181,7 +181,7 @@ function HeaderNym ({ user, isMe }) {
}
function HeaderHeader ({ user }) {
const me = useMe()
const { me } = useMe()
const showModal = useShowModal()
const toaster = useToast()

View File

@ -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 <PageLoading />

View File

@ -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

View File

@ -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({

View File

@ -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 (
<h2 className={`${me ? 'visible' : 'invisible'} ${limitReached ? 'text-warning' : 'text-success'}`}>
@ -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 }

View File

@ -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) {