Allow details and course pages to be accessed with naddr or note id

This commit is contained in:
austinkelsay 2024-10-05 19:35:04 -05:00
parent 58f2a6635a
commit 34e116e9cc
3 changed files with 30 additions and 13 deletions

View File

@ -66,7 +66,11 @@ const SearchBar = () => {
}, [selectedSearchOption, contentResults, communityResults]); }, [selectedSearchOption, contentResults, communityResults]);
const handleContentSelect = (content) => { const handleContentSelect = (content) => {
router.push(`/details/${content.id}`); if (content?.type === 'course') {
router.push(`/course/${content.id}`);
} else {
router.push(`/details/${content.id}`);
}
setSearchTerm(''); setSearchTerm('');
searchContent(''); searchContent('');
op.current.hide(); op.current.hide();

View File

@ -25,13 +25,19 @@ const useCourseData = (ndk, fetchAuthor, router) => {
useEffect(() => { useEffect(() => {
if (router.isReady) { if (router.isReady) {
const { slug } = router.query; const { slug } = router.query;
const { data } = nip19.decode(slug); let id;
if (!data) { if (slug.includes("naddr")) {
showToast('error', 'Error', 'Course not found'); const { data } = nip19.decode(slug);
setLoading(false); if (!data) {
return; showToast('error', 'Error', 'Course not found');
setLoading(false);
return;
}
id = data?.identifier;
} else {
id = slug;
} }
const id = data?.identifier;
const fetchCourse = async (id) => { const fetchCourse = async (id) => {
try { try {
await ndk.connect(); await ndk.connect();

View File

@ -70,19 +70,26 @@ export default function Details() {
if (router.isReady) { if (router.isReady) {
const { slug } = router.query; const { slug } = router.query;
if (!slug) { if (!slug) {
return; return;
} }
const { data } = nip19.decode(slug) let id;
if (!data) { if (slug.includes("naddr")) {
showToast('error', 'Error', 'Resource not found'); const { data } = nip19.decode(slug)
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) => { const fetchEvent = async (id, retryCount = 0) => {
setLoading(true); setLoading(true);
setError(null); setError(null);