From 34e116e9cc86951366005aa5f987353474641aec Mon Sep 17 00:00:00 2001 From: austinkelsay Date: Sat, 5 Oct 2024 19:35:04 -0500 Subject: [PATCH] Allow details and course pages to be accessed with naddr or note id --- src/components/search/SearchBar.js | 6 +++++- src/pages/course/[slug]/index.js | 18 ++++++++++++------ src/pages/details/[slug]/index.js | 19 +++++++++++++------ 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/components/search/SearchBar.js b/src/components/search/SearchBar.js index 7408ea2..9844e3b 100644 --- a/src/components/search/SearchBar.js +++ b/src/components/search/SearchBar.js @@ -66,7 +66,11 @@ const SearchBar = () => { }, [selectedSearchOption, contentResults, communityResults]); const handleContentSelect = (content) => { - router.push(`/details/${content.id}`); + if (content?.type === 'course') { + router.push(`/course/${content.id}`); + } else { + router.push(`/details/${content.id}`); + } setSearchTerm(''); searchContent(''); op.current.hide(); diff --git a/src/pages/course/[slug]/index.js b/src/pages/course/[slug]/index.js index adebbf9..4491bbb 100644 --- a/src/pages/course/[slug]/index.js +++ b/src/pages/course/[slug]/index.js @@ -25,13 +25,19 @@ const useCourseData = (ndk, fetchAuthor, router) => { useEffect(() => { if (router.isReady) { const { slug } = router.query; - const { data } = nip19.decode(slug); - if (!data) { - showToast('error', 'Error', 'Course not found'); - setLoading(false); - return; + let id; + if (slug.includes("naddr")) { + const { data } = nip19.decode(slug); + if (!data) { + showToast('error', 'Error', 'Course not found'); + setLoading(false); + return; + } + id = data?.identifier; + } else { + id = slug; } - const id = data?.identifier; + const fetchCourse = async (id) => { try { await ndk.connect(); diff --git a/src/pages/details/[slug]/index.js b/src/pages/details/[slug]/index.js index dd27a20..19402b0 100644 --- a/src/pages/details/[slug]/index.js +++ b/src/pages/details/[slug]/index.js @@ -70,19 +70,26 @@ export default function Details() { if (router.isReady) { const { slug } = router.query; + if (!slug) { return; } + + let id; - const { data } = nip19.decode(slug) + if (slug.includes("naddr")) { + const { data } = nip19.decode(slug) - if (!data) { - showToast('error', 'Error', 'Resource not found'); - return; + if (!data) { + showToast('error', 'Error', 'Resource not found'); + return; + } + + id = data?.identifier; + } else { + id = slug; } - const id = data?.identifier; - const fetchEvent = async (id, retryCount = 0) => { setLoading(true); setError(null);