chore: migrate to payload / nextjs
This commit is contained in:
15
src/hooks/populatePublishedAt.ts
Normal file
15
src/hooks/populatePublishedAt.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import type { CollectionBeforeChangeHook } from 'payload'
|
||||
|
||||
export const populatePublishedAt: CollectionBeforeChangeHook = ({ data, operation, req }) => {
|
||||
if (operation === 'create' || operation === 'update') {
|
||||
if (req.data && !req.data.publishedAt) {
|
||||
const now = new Date()
|
||||
return {
|
||||
...data,
|
||||
publishedAt: now,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
11
src/hooks/revalidateRedirects.ts
Normal file
11
src/hooks/revalidateRedirects.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import type { CollectionAfterChangeHook } from 'payload'
|
||||
|
||||
import { revalidateTag } from 'next/cache'
|
||||
|
||||
export const revalidateRedirects: CollectionAfterChangeHook = ({ doc, req: { payload } }) => {
|
||||
payload.logger.info(`Revalidating redirects`)
|
||||
|
||||
revalidateTag('redirects', 'max')
|
||||
|
||||
return doc
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
export function useIsMobile(breakpoint = 768): boolean {
|
||||
const [isMobile, setIsMobile] = useState(() => window.innerWidth < breakpoint);
|
||||
useEffect(() => {
|
||||
const mq = window.matchMedia(`(max-width: ${breakpoint - 1}px)`);
|
||||
const handler = (e: MediaQueryListEvent) => setIsMobile(e.matches);
|
||||
mq.addEventListener('change', handler);
|
||||
setIsMobile(mq.matches);
|
||||
return () => mq.removeEventListener('change', handler);
|
||||
}, [breakpoint]);
|
||||
return isMobile;
|
||||
}
|
||||
Reference in New Issue
Block a user