File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 11import type { CollectionConfig } from 'payload'
2+ import { getPayload } from 'payload'
3+ import config from '@payload-config'
4+ import { revalidatePath } from 'next/cache'
5+ import purgeRoute from '@/lib/utils/purge'
6+ import { routing } from '@/i18n/routing'
27
38export const Media : CollectionConfig = {
49 slug : 'media' ,
@@ -33,4 +38,38 @@ export const Media: CollectionConfig = {
3338 } ,
3439 ] ,
3540 } ,
41+ hooks : {
42+ afterChange : [
43+ async ( { req, data } ) => {
44+ const payload = await getPayload ( { config } )
45+
46+ // Determine if the image is a thumbnail of any project.
47+ // Done to update the projects page in case the focal point was changed.
48+ // Individual project update not really required since the image will always be shown
49+ // in its entirety.
50+ const isThumbnail = await payload . find ( {
51+ collection : 'project' ,
52+ where : {
53+ thumbnail : {
54+ equals : data . id ,
55+ } ,
56+ } ,
57+ req,
58+ pagination : false ,
59+ } )
60+
61+ if ( isThumbnail . totalDocs > 0 ) {
62+ if ( req . locale === 'all' ) {
63+ routing . locales . forEach ( ( locale ) => {
64+ revalidatePath ( `/${ locale } /projects` )
65+ purgeRoute ( `${ locale } /projects` )
66+ } )
67+ } else {
68+ revalidatePath ( `/${ req . locale } /projects` )
69+ purgeRoute ( `${ req . locale } /projects` )
70+ }
71+ }
72+ } ,
73+ ] ,
74+ } ,
3675}
You can’t perform that action at this time.
0 commit comments