diff --git a/src/app/worship/[id]/page.tsx b/src/app/worship/[id]/page.tsx
index b915856..a919a18 100644
--- a/src/app/worship/[id]/page.tsx
+++ b/src/app/worship/[id]/page.tsx
@@ -7,7 +7,7 @@ import { Container } from '@/components/Container/Container'
import { Card } from '@/components/Card/Card'
import styles from './styles.module.css'
import { MassTitle } from '@/components/MassTitle/MassTitle'
-import { useCompactDate, useDate } from '@/hooks/useCompactDate'
+import { useDate } from '@/hooks/useCompactDate'
import { useTime } from '@/hooks/useTime'
import { Pill } from '@/components/Pill/Pill'
import { useMassType } from '@/hooks/useMassType'
@@ -17,6 +17,7 @@ import locationIcon from './location.svg'
import question from './question.svg'
import { LocationMap } from '@/components/Map/Map'
import { Testimony } from '@/components/Testimony/Testimony'
+import { randomTestimony } from '@/utils/randomTestimony'
export default async function Page({ params }: { params: { id: string } }) {
const payload = await getPayloadHMR({ config: configPromise })
@@ -24,6 +25,7 @@ export default async function Page({ params }: { params: { id: string } }) {
id: params.id,
collection: 'worship',
})
+ const testimony = await randomTestimony('EUCHARIST')
const location = useLocation(worship.location)
const title = useLiturgyCalendarTitle(worship.date)
const date = useDate(worship.date)
@@ -92,10 +94,9 @@ export default async function Page({ params }: { params: { id: string } }) {
>
)
diff --git a/src/collections/Testimony.ts b/src/collections/Testimony.ts
index 372118d..9c399b2 100644
--- a/src/collections/Testimony.ts
+++ b/src/collections/Testimony.ts
@@ -50,4 +50,7 @@ export const Testimony: CollectionConfig = {
required: true,
},
],
+ access: {
+ read: () => true,
+ },
}
diff --git a/src/components/Menu/styles.module.css b/src/components/Menu/styles.module.css
index 432f011..7818452 100644
--- a/src/components/Menu/styles.module.css
+++ b/src/components/Menu/styles.module.css
@@ -1,6 +1,6 @@
.nav {
display: flex;
- align-items: baseline;
+ align-items: center;
gap: 20px;
color: #1f1f1f;
padding: 15px;
diff --git a/src/utils/randomTestimony.ts b/src/utils/randomTestimony.ts
new file mode 100644
index 0000000..0874028
--- /dev/null
+++ b/src/utils/randomTestimony.ts
@@ -0,0 +1,35 @@
+import { getPayloadHMR } from '@payloadcms/next/utilities'
+import configPromise from '@payload-config'
+import { unstable_cache } from 'next/cache'
+
+type Category = 'EUCHARIST'
+
+/**
+ * Fetch testimonials from database
+ */
+const fetchTestimonies = async (type: Category) => {
+ const payload = await getPayloadHMR({ config: configPromise })
+ return await payload.find({
+ collection: 'testimony',
+ sort: 'createdAt',
+ where: {
+ category: {
+ equals: type,
+ },
+ },
+ })
+}
+
+/**
+ * Fetch a random cached testimony
+ */
+export const randomTestimony = async (type: Category) => {
+ const testimonials = await unstable_cache(
+ () => fetchTestimonies(type),
+ ['testimony', type],
+ { revalidate: 3600 },
+ )()
+ const length = testimonials.docs.length
+ const randomIndex = Math.floor(Math.random() * length)
+ return testimonials.docs[randomIndex]
+}