Cache forms #187
@ -22,7 +22,7 @@ import {
|
||||
ModFormState,
|
||||
ModPageLoaderResult
|
||||
} from '../types'
|
||||
import { initializeFormState } from '../utils'
|
||||
import { initializeFormState, MOD_DRAFT_CACHE_KEY } from '../utils'
|
||||
import { CheckboxField, InputField, InputFieldWithImageUpload } from './Inputs'
|
||||
import { OriginalAuthor } from './OriginalAuthor'
|
||||
import { CategoryAutocomplete } from './CategoryAutocomplete'
|
||||
@ -49,7 +49,8 @@ export const ModForm = () => {
|
||||
|
||||
// Enable cache for the new mod
|
||||
const isEditing = typeof mod !== 'undefined'
|
||||
const [cache, setCache, clearCache] = useLocalCache<ModFormState>('draft-mod')
|
||||
const [cache, setCache, clearCache] =
|
||||
useLocalCache<ModFormState>(MOD_DRAFT_CACHE_KEY)
|
||||
const [formState, setFormState] = useState<ModFormState>(
|
||||
isEditing ? initializeFormState(mod) : cache ? cache : initializeFormState()
|
||||
)
|
||||
|
@ -12,7 +12,9 @@ import {
|
||||
isValidUrl,
|
||||
log,
|
||||
LogType,
|
||||
now
|
||||
MOD_DRAFT_CACHE_KEY,
|
||||
now,
|
||||
removeLocalStorageItem
|
||||
} from 'utils'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { T_TAG_VALUE } from '../../constants'
|
||||
@ -141,6 +143,8 @@ export const submitModRouteAction =
|
||||
)}`
|
||||
)
|
||||
|
||||
!isEditing && removeLocalStorageItem(MOD_DRAFT_CACHE_KEY)
|
||||
|
||||
const naddr = nip19.naddrEncode({
|
||||
identifier: aTag,
|
||||
pubkey: signedEvent.pubkey,
|
||||
|
@ -2,7 +2,15 @@ import { NDKContextType } from 'contexts/NDKContext'
|
||||
import { ActionFunctionArgs, redirect } from 'react-router-dom'
|
||||
import { getBlogPageRoute } from 'routes'
|
||||
import { BlogFormErrors, BlogEventSubmitForm, BlogEventEditForm } from 'types'
|
||||
import { isReachable, isValidImageUrl, log, LogType, now } from 'utils'
|
||||
import {
|
||||
BLOG_DRAFT_CACHE_KEY,
|
||||
isReachable,
|
||||
isValidImageUrl,
|
||||
log,
|
||||
LogType,
|
||||
now,
|
||||
removeLocalStorageItem
|
||||
} from 'utils'
|
||||
import { kinds, UnsignedEvent, Event, nip19 } from 'nostr-tools'
|
||||
import { toast } from 'react-toastify'
|
||||
import { NDKEvent } from '@nostr-dev-kit/ndk'
|
||||
@ -118,6 +126,9 @@ export const writeRouteAction =
|
||||
'\n'
|
||||
)}`
|
||||
)
|
||||
|
||||
!isEditing && removeLocalStorageItem(BLOG_DRAFT_CACHE_KEY)
|
||||
|
||||
const naddr = nip19.naddrEncode({
|
||||
identifier: uuid,
|
||||
pubkey: signedEvent.pubkey,
|
||||
|
@ -22,7 +22,7 @@ import { LoadingSpinner } from 'components/LoadingSpinner'
|
||||
import { AlertPopup } from 'components/AlertPopup'
|
||||
import { Editor, EditorRef } from 'components/Markdown/Editor'
|
||||
import { InputError } from 'components/Inputs/Error'
|
||||
import { initializeBlogForm } from 'utils'
|
||||
import { BLOG_DRAFT_CACHE_KEY, initializeBlogForm } from 'utils'
|
||||
import 'styles/innerPage.css'
|
||||
import 'styles/styles.css'
|
||||
import 'styles/write.css'
|
||||
@ -40,7 +40,7 @@ export const WritePage = () => {
|
||||
// Enable cache for the new blog
|
||||
const isEditing = typeof data?.blog !== 'undefined'
|
||||
const [cache, setCache, clearCache] =
|
||||
useLocalCache<BlogEventSubmitForm>('draft-blog')
|
||||
useLocalCache<BlogEventSubmitForm>(BLOG_DRAFT_CACHE_KEY)
|
||||
|
||||
const title = isEditing ? 'Edit blog post' : 'Submit a blog post'
|
||||
const [formState, setFormState] = useState<
|
||||
|
@ -75,3 +75,5 @@ export const initializeBlogForm = (
|
||||
published_at: blog.published_at
|
||||
})
|
||||
})
|
||||
|
||||
export const BLOG_DRAFT_CACHE_KEY = 'draft-blog'
|
||||
|
@ -146,3 +146,5 @@ export const initializeFormState = (
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
export const MOD_DRAFT_CACHE_KEY = 'draft-mod'
|
||||
|
Loading…
x
Reference in New Issue
Block a user