From 1e183c50515302d099078cc1bf4fe690c05422e4 Mon Sep 17 00:00:00 2001 From: Nick Winters Date: Sun, 25 Aug 2024 19:38:46 -0700 Subject: [PATCH] Search hook fixes --- app/_custom/hooks/search-hooks.ts | 4 ++-- app/db/collections/collections/collections-hooks.ts | 11 ++++++++++- app/db/collections/custom-pages/custom-pages-hooks.ts | 10 +++++++++- app/db/collections/entries/entries-hooks.ts | 11 ++++++++++- app/db/collections/posts/posts-hooks.ts | 11 ++++++++++- app/db/collections/users/users.config.ts | 4 +++- app/routes/_user+/components/UserMenuItems.tsx | 2 +- package.json | 3 ++- scripts/resaveCollection.ts | 4 ++-- 9 files changed, 49 insertions(+), 11 deletions(-) diff --git a/app/_custom/hooks/search-hooks.ts b/app/_custom/hooks/search-hooks.ts index 2a914ad12..2a4a591c1 100644 --- a/app/_custom/hooks/search-hooks.ts +++ b/app/_custom/hooks/search-hooks.ts @@ -56,14 +56,14 @@ export const afterChangeSearchSyncHook: CollectionAfterChangeHook = async ({ //Due to the way Payload handles depth in relationships, we need to fetch the icon URL if it exists const { url: iconUrl } = doc?.icon?.url - ? doc?.icon + ? { url: doc?.icon?.url } : doc?.icon ? await payload.findByID({ collection: "images", id: doc?.icon, depth: 0, }) - : null; + : { url: null }; await typesensePrivateClient .collections("entries") diff --git a/app/db/collections/collections/collections-hooks.ts b/app/db/collections/collections/collections-hooks.ts index 9b1b7bf29..03cd052e0 100644 --- a/app/db/collections/collections/collections-hooks.ts +++ b/app/db/collections/collections/collections-hooks.ts @@ -63,7 +63,16 @@ export const collectionsAfterChangeHook: CollectionAfterChangeHook = async ({ doc?.site?.domain ? doc?.site?.domain : `${doc?.site?.slug}.mana.wiki` }${collectionRelativeURL}`; - const iconUrl = doc?.icon?.url; + //Due to the way Payload handles depth in relationships, we need to fetch the icon URL if it exists + const { url: iconUrl } = doc?.icon?.url + ? { url: doc?.icon?.url } + : doc?.icon + ? await payload.findByID({ + collection: "images", + id: doc?.icon, + depth: 0, + }) + : { url: null }; await typesensePrivateClient .collections("collections") diff --git a/app/db/collections/custom-pages/custom-pages-hooks.ts b/app/db/collections/custom-pages/custom-pages-hooks.ts index d5b06c840..a3c04f26e 100644 --- a/app/db/collections/custom-pages/custom-pages-hooks.ts +++ b/app/db/collections/custom-pages/custom-pages-hooks.ts @@ -44,7 +44,15 @@ export const customPagesAfterChangeHook: CollectionAfterChangeHook = async ({ const description = doc?.description; - const iconUrl = doc?.icon?.url; + const { url: iconUrl } = doc?.icon?.url + ? { url: doc?.icon?.url } + : doc?.icon + ? await payload.findByID({ + collection: "images", + id: doc?.icon, + depth: 0, + }) + : { url: null }; await typesensePrivateClient .collections("customPages") diff --git a/app/db/collections/entries/entries-hooks.ts b/app/db/collections/entries/entries-hooks.ts index 535f71b3c..0d6370c61 100644 --- a/app/db/collections/entries/entries-hooks.ts +++ b/app/db/collections/entries/entries-hooks.ts @@ -49,7 +49,16 @@ export const entriesAfterChangeHook: CollectionAfterChangeHook = async ({ doc?.site?.domain ? doc?.site?.domain : `${doc?.site?.slug}.mana.wiki` }${entryRelativeURL}`; - const iconUrl = doc?.icon?.url; + const { url: iconUrl } = doc?.icon?.url + ? { url: doc?.icon?.url } + : doc?.icon + ? await payload.findByID({ + collection: "images", + id: doc?.icon, + depth: 0, + }) + : { url: null }; + const description = doc?.collectionEntity?.name; await typesensePrivateClient diff --git a/app/db/collections/posts/posts-hooks.ts b/app/db/collections/posts/posts-hooks.ts index ed6ddf1ee..abb9f20ce 100644 --- a/app/db/collections/posts/posts-hooks.ts +++ b/app/db/collections/posts/posts-hooks.ts @@ -51,7 +51,16 @@ export const postsAfterChangeHook: CollectionAfterChangeHook = async ({ : `${doc?.site?.slug}.mana.wiki` }${postRelativeURL}`; - const bannerUrl = doc?.banner?.url; + //Due to the way Payload handles depth in relationships, we need to fetch the icon URL if it exists + const { url: bannerUrl } = doc?.banner?.url + ? { url: doc?.banner?.url } + : doc?.banner + ? await payload.findByID({ + collection: "images", + id: doc?.banner, + depth: 0, + }) + : { url: null }; const description = doc?.subtitle; await typesensePrivateClient diff --git a/app/db/collections/users/users.config.ts b/app/db/collections/users/users.config.ts index 399878183..b5f101d17 100644 --- a/app/db/collections/users/users.config.ts +++ b/app/db/collections/users/users.config.ts @@ -26,7 +26,9 @@ export const Users: CollectionConfig = { }/verify?token=${token}`; return ` - Hey ${user.email}, thanks for registering at Mana. + Hey ${user.email}, thanks for registering at ${ + process.env.HOST_DOMAIN ?? "mana.wiki" + }

diff --git a/app/routes/_user+/components/UserMenuItems.tsx b/app/routes/_user+/components/UserMenuItems.tsx index f864589e4..b6b920f8d 100644 --- a/app/routes/_user+/components/UserMenuItems.tsx +++ b/app/routes/_user+/components/UserMenuItems.tsx @@ -5,7 +5,7 @@ export function UserMenuItems() {
- + {/* */}
); } diff --git a/package.json b/package.json index 64f9c7183..f8fde3f26 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "clean": "shx rm -rf node_modules dist build public/build", "seed:core": "cross-env PAYLOAD_CONFIG_PATH=./app/db/payload.config.ts ts-node -T app/_custom/seed/index.ts", "seed:custom": "cross-env PAYLOAD_CONFIG_PATH=./app/db/payload.custom.config.ts ts-node -T app/_custom/seed/index.ts", - "resave": "cross-env PAYLOAD_CONFIG_PATH=./app/db/payload.custom.config.ts ts-node -T ./scripts/resaveCollection", + "resaveCore": "cross-env PAYLOAD_CONFIG_PATH=./app/db/payload.config.ts ts-node -T ./scripts/resaveCollection", + "resaveCustom": "cross-env PAYLOAD_CONFIG_PATH=./app/db/payload.custom.config.ts ts-node -T ./scripts/resaveCollection", "typesense": "cross-env ts-node -T ./scripts/typesenseActions", "postinstall": "patch-package" }, diff --git a/scripts/resaveCollection.ts b/scripts/resaveCollection.ts index 59751fd27..c9c2385ef 100644 --- a/scripts/resaveCollection.ts +++ b/scripts/resaveCollection.ts @@ -1,6 +1,6 @@ import Payload from "payload"; -import { manaSlug } from "../app/utils/url-slug"; +// import { manaSlug } from "../app/utils/url-slug"; require("dotenv").config(); @@ -41,7 +41,7 @@ const resaveCollection = async () => { await payload.update({ collection: collectionSlug, id, - depth: 0, + depth: 2, data: { updatedAt: new Date(), // slug: manaSlug(result.name),