mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-05 00:32:03 +00:00
Update src/hooks/courses/useCourseData.js
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
parent
f8bd1ddb43
commit
bac65c0dd3
@ -24,8 +24,22 @@ const useCourseData = (ndk, fetchAuthor, router) => {
|
|||||||
let id;
|
let id;
|
||||||
|
|
||||||
const fetchCourseId = async () => {
|
const fetchCourseId = async () => {
|
||||||
if (slug.includes('naddr')) {
|
// Normalise slug to a string and exit early if it’s still falsy
|
||||||
const { data } = nip19.decode(slug);
|
const slugStr = Array.isArray(slug) ? slug[0] : slug;
|
||||||
|
if (!slugStr) {
|
||||||
|
showToast('error', 'Error', 'Invalid course identifier');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (slugStr.includes('naddr')) {
|
||||||
|
let data;
|
||||||
|
try {
|
||||||
|
({ data } = nip19.decode(slugStr));
|
||||||
|
} catch (err) {
|
||||||
|
showToast('error', 'Error', 'Malformed naddr');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!data?.identifier) {
|
if (!data?.identifier) {
|
||||||
showToast('error', 'Error', 'Resource not found');
|
showToast('error', 'Error', 'Resource not found');
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user