Merge pull request 'staging' (#23) from staging into master
All checks were successful
Release to Staging / build_and_release (push) Successful in 43s

Reviewed-on: #23
This commit is contained in:
s 2024-08-26 13:57:06 +00:00
commit 54ec62df1a
5 changed files with 42 additions and 45 deletions

View File

@ -25,8 +25,8 @@ import {
} from '../utils'
import { CheckboxField, InputError, InputField } from './Inputs'
import { RelayController } from '../controllers'
import { useNavigate } from 'react-router-dom'
import { getModsInnerPageRoute } from '../routes'
import { useLocation, useNavigate } from 'react-router-dom'
import { appRoutes, getModsInnerPageRoute } from '../routes'
import { DownloadUrl, ModFormState, ModDetails } from '../types'
import { LoadingSpinner } from './LoadingSpinner'
import { T_TAG_VALUE } from '../constants'
@ -55,6 +55,7 @@ type ModFormProps = {
}
export const ModForm = ({ existingModData }: ModFormProps) => {
const location = useLocation()
const navigate = useNavigate()
const userState = useAppSelector((state) => state.user)
@ -64,6 +65,12 @@ export const ModForm = ({ existingModData }: ModFormProps) => {
initializeFormState(existingModData)
)
useEffect(() => {
if (location.pathname === appRoutes.submitMod) {
setFormState(initializeFormState())
}
}, [location.pathname]) // Only trigger when the pathname changes to submit-mod
const [formErrors, setFormErrors] = useState<FormErrors>({})
useEffect(() => {
@ -204,6 +211,9 @@ export const ModForm = ({ existingModData }: ModFormProps) => {
const uuid = uuidv4()
const currentTimeStamp = now()
const aTag =
formState.aTag || `${kinds.ClassifiedListing}:${hexPubkey}:${uuid}`
const unsignedEvent: UnsignedEvent = {
kind: kinds.ClassifiedListing,
created_at: currentTimeStamp,
@ -211,10 +221,7 @@ export const ModForm = ({ existingModData }: ModFormProps) => {
content: formState.body,
tags: [
['d', formState.dTag || uuid],
[
'a',
formState.aTag || `${kinds.ClassifiedListing}:${hexPubkey}:${uuid}`
],
['a', aTag],
['r', formState.rTag],
['t', T_TAG_VALUE],
[
@ -267,14 +274,14 @@ export const ModForm = ({ existingModData }: ModFormProps) => {
)}`
)
const nevent = nip19.neventEncode({
id: signedEvent.id,
author: signedEvent.pubkey,
const naddr = nip19.naddrEncode({
identifier: aTag,
pubkey: signedEvent.pubkey,
kind: signedEvent.kind,
relays: publishedOnRelays
})
navigate(getModsInnerPageRoute(nevent))
navigate(getModsInnerPageRoute(naddr))
}
setIsPublishing(false)

View File

@ -40,26 +40,21 @@ import { ZapButtons, ZapPresets, ZapQR } from '../components/Zap'
import { getModsEditPageRoute } from '../routes'
export const InnerModPage = () => {
const { nevent } = useParams()
const { naddr } = useParams()
const [modData, setModData] = useState<ModDetails>()
const [isFetching, setIsFetching] = useState(true)
useDidMount(async () => {
if (nevent) {
const decoded = nip19.decode<'nevent'>(nevent as `nevent1${string}`)
const eventId = decoded.data.id
const kind = decoded.data.kind
const author = decoded.data.author
const relays = decoded.data.relays || []
if (naddr) {
const decoded = nip19.decode<'naddr'>(naddr as `naddr1${string}`)
const { identifier, kind, pubkey, relays = [] } = decoded.data
const filter: Filter = {
ids: [eventId]
'#a': [identifier],
authors: [pubkey],
kinds: [kind]
}
if (kind) filter.kinds = [kind]
if (author) filter.authors = [author]
RelayController.getInstance()
.fetchEvent(filter, relays)
.then((event) => {
@ -115,7 +110,7 @@ export const InnerModPage = () => {
<div className='IBMSMSplitMainBigSide'>
<div className='IBMSMSplitMainBigSideSec'>
<Game
nevent={nevent!}
naddr={naddr!}
game={modData.game}
author={modData.author}
/>
@ -198,12 +193,12 @@ export const InnerModPage = () => {
}
type GameProps = {
nevent: string
naddr: string
game: string
author: string
}
const Game = ({ nevent, game, author }: GameProps) => {
const Game = ({ naddr, game, author }: GameProps) => {
const navigate = useNavigate()
const userState = useAppSelector((state) => state.user)
@ -241,7 +236,7 @@ const Game = ({ nevent, game, author }: GameProps) => {
{userState.auth && userState.user?.pubkey === author && (
<a
className='dropdown-item dropdownMainMenuItem'
onClick={() => navigate(getModsEditPageRoute(nevent))}
onClick={() => navigate(getModsEditPageRoute(naddr))}
>
<svg
xmlns='http://www.w3.org/2000/svg'

View File

@ -176,9 +176,9 @@ export const ModsPage = () => {
handleClick={() =>
navigate(
getModsInnerPageRoute(
nip19.neventEncode({
id: mod.id,
author: mod.author,
nip19.naddrEncode({
identifier: mod.aTag,
pubkey: mod.author,
kind: kinds.ClassifiedListing
})
)

View File

@ -15,7 +15,7 @@ import { useDidMount } from '../hooks'
export const SubmitModPage = () => {
const location = useLocation()
const { nevent } = useParams()
const { naddr } = useParams()
const [modData, setModData] = useState<ModDetails>()
const [isFetching, setIsFetching] = useState(false)
@ -24,21 +24,16 @@ export const SubmitModPage = () => {
: 'Submit a mod'
useDidMount(async () => {
if (nevent) {
const decoded = nip19.decode<'nevent'>(nevent as `nevent1${string}`)
const eventId = decoded.data.id
const kind = decoded.data.kind
const author = decoded.data.author
const relays = decoded.data.relays || []
if (naddr) {
const decoded = nip19.decode<'naddr'>(naddr as `naddr1${string}`)
const { identifier, kind, pubkey, relays = [] } = decoded.data
const filter: Filter = {
ids: [eventId]
'#a': [identifier],
authors: [pubkey],
kinds: [kind]
}
if (kind) filter.kinds = [kind]
if (author) filter.authors = [author]
setIsFetching(true)
RelayController.getInstance()
.fetchEvent(filter, relays)

View File

@ -13,11 +13,11 @@ export const appRoutes = {
home: '/home',
games: '/games',
mods: '/mods',
modsInner: '/mods-inner/:nevent',
modsInner: '/mods-inner/:naddr',
about: '/about',
blog: '/blog',
submitMod: '/submit-mod',
editMod: '/edit-mod/:nevent',
editMod: '/edit-mod/:naddr',
write: '/write',
settingsProfile: '/settings-profile',
settingsRelays: '/settings-relays',
@ -26,10 +26,10 @@ export const appRoutes = {
}
export const getModsInnerPageRoute = (eventId: string) =>
appRoutes.modsInner.replace(':nevent', eventId)
appRoutes.modsInner.replace(':naddr', eventId)
export const getModsEditPageRoute = (eventId: string) =>
appRoutes.editMod.replace(':nevent', eventId)
appRoutes.editMod.replace(':naddr', eventId)
export const routes = [
{