fix related resources rendering

This commit is contained in:
2025-05-23 14:34:04 +02:00
parent 616d03231a
commit 81053d56f7
2 changed files with 8 additions and 6 deletions

View File

@@ -453,7 +453,11 @@ class Network {
async getResourceDetails(id: number): Promise<Response<ResourceDetails>> { async getResourceDetails(id: number): Promise<Response<ResourceDetails>> {
try { try {
const response = await axios.get(`${this.apiBaseUrl}/resource/${id}`) const response = await axios.get(`${this.apiBaseUrl}/resource/${id}`)
return response.data let data = response.data
if (!data.related) {
data.related = []
}
return data
} catch (e: any) { } catch (e: any) {
console.error(e) console.error(e)
return { return {

View File

@@ -229,15 +229,13 @@ function Article({ resource }: { resource: ResourceDetails }) {
useEffect(() => { useEffect(() => {
if (articleRef.current) { if (articleRef.current) {
console.log("render") if (!resource.related) {
return;
}
for (let child of articleRef.current.children) { for (let child of articleRef.current.children) {
console.log("child", child)
if (child.tagName === "P" && child.children.length === 1 && child.children[0].tagName === "A") { if (child.tagName === "P" && child.children.length === 1 && child.children[0].tagName === "A") {
const href = (child.children[0] as HTMLAnchorElement).href as string const href = (child.children[0] as HTMLAnchorElement).href as string
console.log("href", href)
console.log("origin", window.location.origin)
if (href.startsWith(window.location.origin) || href.startsWith("/")) { if (href.startsWith(window.location.origin) || href.startsWith("/")) {
console.log("href starts with origin")
let path = href let path = href
if (path.startsWith(window.location.origin)) { if (path.startsWith(window.location.origin)) {
path = path.substring(window.location.origin.length) path = path.substring(window.location.origin.length)