Skip to content

Commit

Permalink
Running linter
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinKelsay committed Sep 26, 2023
1 parent 9001223 commit 20abbc6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 48 deletions.
8 changes: 4 additions & 4 deletions components/adv-post-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ export default function AdvPostForm () {
<li>we use your NIP-05 relays if set</li>
<li>otherwise we default to these relays:</li>
<ul>
{DEFAULT_CROSSPOSTING_RELAYS.map((relay, i) => (
<li key={i}>{relay}</li>
))}
{DEFAULT_CROSSPOSTING_RELAYS.map((relay, i) => (
<li key={i}>{relay}</li>
))}
</ul>
</ul>
</Info>
</div>
}
name='crosspost'
hint={<span className='text-muted'>crosspost to nostr</span>}
/>
/>
</>
}
/>
Expand Down
72 changes: 38 additions & 34 deletions components/discussion-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ import { discussionSchema } from '../lib/validate'
import { SubSelectInitial } from './sub-select-form'
import CancelButton from './cancel-button'
import { useCallback } from 'react'
import { crosspostDiscussion } from '../lib/nostr'
import { crosspostDiscussion, DEFAULT_CROSSPOSTING_RELAYS } from '../lib/nostr'
import { normalizeForwards } from '../lib/form'
import { MAX_TITLE_LENGTH } from '../lib/constants'
import {DEFAULT_CROSSPOSTING_RELAYS} from '../lib/nostr'
import { useMe } from './me'
import { useToast } from './toast'

export function DiscussionForm({
export function DiscussionForm ({
item, sub, editThreshold, titleLabel = 'title',
textLabel = 'text', buttonText = 'post',
handleSubmit, children
Expand All @@ -32,7 +31,7 @@ export function DiscussionForm({
// if Web Share Target API was used
const shareTitle = router.query.title
const Toast = useToast()
const relays = [...DEFAULT_CROSSPOSTING_RELAYS, ...me?.nostrRelays || []];
const relays = [...DEFAULT_CROSSPOSTING_RELAYS, ...me?.nostrRelays || []]

const [upsertDiscussion] = useMutation(
gql`
Expand All @@ -47,51 +46,56 @@ export function DiscussionForm({
return new Promise((resolve) => {
const { removeToast } = Toast.danger(
<>
Crossposting failed for {failedRelays.join(", ")} <br />
<Button variant="link" onClick={() => {
resolve('retry');
setTimeout(() => {
removeToast();
}, 1000);
}}>Retry</Button>
{" | "}
<Button variant="link" onClick={() => {
resolve('skip');
}}>Skip</Button>
Crossposting failed for {failedRelays.join(', ')} <br />
<Button
variant='link' onClick={() => {
resolve('retry')
setTimeout(() => {
removeToast()
}, 1000)
}}
>Retry
</Button>
{' | '}
<Button
variant='link' onClick={() => {
resolve('skip')
}}
>Skip
</Button>
</>,
() => resolve('skip') // will skip if user closes the toast
);
});
};
)
})
}

const handleCrosspost = async (values, id) => {
let failedRelays;
let allSuccessful = false;
let failedRelays
let allSuccessful = false

do {
let result = await crosspostDiscussion(values, id, failedRelays || relays);
const result = await crosspostDiscussion(values, id, failedRelays || relays)

result.successfulRelays.forEach(relay => {
Toast.success(`Crossposting succeeded on relay ${relay}`);
});
Toast.success(`Crossposting succeeded on relay ${relay}`)
})

failedRelays = result.failedRelays.map(relayObj => relayObj.relay);
failedRelays = result.failedRelays.map(relayObj => relayObj.relay)

if (failedRelays.length > 0) {
const userAction = await relayError(failedRelays);
const userAction = await relayError(failedRelays)

if (userAction === 'skip') {
Toast.success("Crossposting skipped.");
break;
Toast.success('Crossposting skipped.')
break
}
} else {
allSuccessful = true;
allSuccessful = true
}
} while (failedRelays.length > 0)

} while (failedRelays.length > 0);

return { allSuccessful };
};
return { allSuccessful }
}

const onSubmit = useCallback(
async ({ boost, crosspost, ...values }) => {
Expand All @@ -112,7 +116,7 @@ export function DiscussionForm({
const shouldCrosspost = me?.nostrCrossposting && crosspost

if (shouldCrosspost && data?.upsertDiscussion?.id) {
const results = await handleCrosspost(values, data.upsertDiscussion.id);
const results = await handleCrosspost(values, data.upsertDiscussion.id)
if (results.allSuccessful) {
if (item) {
await router.push(`/items/${item.id}`)
Expand Down
10 changes: 5 additions & 5 deletions components/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ export const ToastProvider = ({ children }) => {
})
},
danger: (body, onCloseCallback) => {
const id = toastId.current;
const id = toastId.current
dispatchToast({
id,
body,
variant: 'danger',
autohide: false,
onCloseCallback,
onCloseCallback
})
return {
removeToast: () => removeToast(id)
};
}
}
}), [dispatchToast])

Expand Down Expand Up @@ -74,8 +74,8 @@ export const ToastProvider = ({ children }) => {
className='p-0 ps-2'
aria-label='close'
onClick={() => {
if (toast.onCloseCallback) toast.onCloseCallback();
removeToast(toast.id);
if (toast.onCloseCallback) toast.onCloseCallback()
removeToast(toast.id)
}}
><div className={styles.toastClose}>X</div>
</Button>
Expand Down
9 changes: 4 additions & 5 deletions pages/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import Info from '../components/info'
import Link from 'next/link'
import AccordianItem from '../components/accordian-item'
import { bech32 } from 'bech32'
import { NOSTR_MAX_RELAY_NUM, NOSTR_PUBKEY_BECH32 } from '../lib/nostr'
import { NOSTR_MAX_RELAY_NUM, NOSTR_PUBKEY_BECH32, DEFAULT_CROSSPOSTING_RELAYS } from '../lib/nostr'
import { emailSchema, lastAuthRemovalSchema, settingsSchema } from '../lib/validate'
import { SUPPORTED_CURRENCIES } from '../lib/currency'
import {DEFAULT_CROSSPOSTING_RELAYS} from '../lib/nostr'
import PageLoading from '../components/page-loading'
import { useShowModal } from '../components/modal'
import { authErrorMessage } from '../components/login'
Expand Down Expand Up @@ -322,9 +321,9 @@ export default function Settings ({ ssrData }) {
<li>we use your NIP-05 relays if set</li>
<li>otherwise we default to these relays:</li>
<ul>
{DEFAULT_CROSSPOSTING_RELAYS.map((relay, i) => (
<li key={i}>{relay}</li>
))}
{DEFAULT_CROSSPOSTING_RELAYS.map((relay, i) => (
<li key={i}>{relay}</li>
))}
</ul>
</ul>
</Info>
Expand Down

0 comments on commit 20abbc6

Please sign in to comment.