Skip to content

Commit

Permalink
test clearing cache post api update
Browse files Browse the repository at this point in the history
  • Loading branch information
viet nguyen committed Nov 12, 2023
1 parent e4405fc commit 6c1fa73
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
typescript: {
ignoreBuildErrors: false
},
generateEtags: false,
// generateEtags: false,
webpack (config) { // required by @svgr/webpack lib
const fileLoaderRule = config.module.rules.find((rule) => rule.test?.test?.('.svg'))

Expand Down
5 changes: 5 additions & 0 deletions src/app/area/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { StickyHeaderContainer } from '@/app/components/ui/StickyHeaderContainer

import BreadCrumbs from '@/components/ui/BreadCrumbs'

/**
* Cache duration in seconds
*/
export const revalidate = 30

export interface PageWithCatchAllUuidProps {
params: {
slug: string[]
Expand Down
1 change: 1 addition & 0 deletions src/app/editArea/[slug]/attributes/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DashboardPageProps, getPageDataForEdit, PageContainer } from '../page'
export default async function AreaEditPage ({ params }: DashboardPageProps): Promise<any> {
const { area: { uuid, metadata: { lat, lng } } } = await getPageDataForEdit(params.slug)

console.log('#', lat, lng)
return (
<PageContainer>
<AreaLatLngForm initLat={lat} initLng={lng} uuid={uuid} />
Expand Down
2 changes: 1 addition & 1 deletion src/app/editArea/[slug]/general/AreaLatLngForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const AreaLatLngForm: React.FC<{ initLat: number, initLng: number, uuid:
}}
>
<DashboardInput
name='latlng'
name='latlngStr'
label='Coordinates'
description='Specify the approximate latitude and longitude. The location may be where the trail meets the wall or in the middle of a long wall.'
helper='Please use <latitude>, <longitude>'
Expand Down
2 changes: 1 addition & 1 deletion src/app/editArea/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface DashboardPageProps {
}

export default async function AreaEditPage ({ params }: DashboardPageProps): Promise<any> {
const { area: { areaName, uuid, content: { description }, metadata: { lat, lng } } } = await getPageDataForEdit(params.slug)
const { area: { areaName, uuid, content: { description } } } = await getPageDataForEdit(params.slug)
return (
<PageContainer>
<AreaNameForm initialValue={areaName} uuid={uuid} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/crag/StickyHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef, ReactNode } from 'react'
import { useRef } from 'react'
import { useIntersection } from 'react-use'
import clx from 'classnames'

Expand Down
1 change: 0 additions & 1 deletion src/components/editor/plugins/ReactHookFormFieldPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const ReactHookFormFieldPlugin: React.FC<{ fieldName: string, rules?: Rul
const onChange = useCallback((editorState: EditorState): void => {
editorState.read(() => {
const str = $getRoot().getTextContent()
console.log('#updating form')
field.onChange(str)
})
}, [editor])
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/form/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FormState, RegisterOptions, useFormContext, UseFormReturn } from 'react-hook-form'
import { RegisterOptions, useFormContext, UseFormReturn } from 'react-hook-form'
import clx from 'classnames'
import { SpinnerGap } from '@phosphor-icons/react/dist/ssr'

Expand Down
8 changes: 7 additions & 1 deletion src/js/hooks/useUpdateAreasCmd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ export default function useUpdateAreasCmd ({ areaId, accessToken = '', ...props
})
}

const [updateAreaApi] = useMutation<{ updateAreaApi: UpdateAreaApiReturnType }, UpdateOneAreaInputType>(
const [updateAreaApi] = useMutation<{ updateArea: UpdateAreaApiReturnType }, UpdateOneAreaInputType>(
MUTATION_UPDATE_AREA, {
client: graphqlClient,
onCompleted: (data) => {
console.log('#onCompleted', data)
toast.info('Area updated successfully ✔️')
void updateCache(data.updateArea.uuid)
void refreshPage(`/api/revalidate?s=${areaId}`)
if (onUpdateCompleted != null) onUpdateCompleted(data)
},
Expand Down Expand Up @@ -190,3 +192,7 @@ export const refreshPage = async (url: string): Promise<void> => {
await fetch(url)
} catch {}
}

const updateCache = async (uuid: string): Promise<void> => {
await fetch(`/editArea/${uuid}/updateCache`)
}

0 comments on commit 6c1fa73

Please sign in to comment.