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