Commit 3502c0bb authored by Fabien Amarger's avatar Fabien Amarger
Browse files

feat: [dublincore] Use a dedicated props interface for the DublinCoreElement

This interface is easier thant the dcschema one, since the
simpleRender is reducted to the necessary needs.
parent 10091d9a8169
Pipeline #11402 failed with stages
in 2 minutes and 45 seconds
import * as React from "react";
import { DublinCoreElement } from "./dcschema";
import * as ReactMarkdown from "react-markdown";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faBook } from "@fortawesome/free-solid-svg-icons";
export interface DublinCoreElement {
typeUri?: string;
title: string;
description: string;
creator: string;
date: string;
contentType: string;
}
export const DublinCoreElementComponent: React.FC<{
dcelement: DublinCoreElement;
}> = ({ dcelement }) => {
......@@ -13,7 +24,13 @@ export const DublinCoreElementComponent: React.FC<{
return (
<>
<h1>{dcelement.title}</h1>
<h1>
{dcelement.typeUri !== undefined &&
dcelement.typeUri.endsWith("Book") && (
<FontAwesomeIcon icon={faBook} />
)}
{dcelement.title}
</h1>
<div>{dcelement.creator}</div>
<div>{dcelement.date}</div>
{contentDisplay}
......
......@@ -101,15 +101,26 @@ class DCElementRendering implements implementation.ViewImplementation {
simpleRender(context: $rdf.Formula, target: string): Element {
const DCT = $rdf.Namespace("http://purl.org/dc/elements/1.1/");
const title: any = context.any(
$rdf.sym(target),
DCT("title"),
undefined,
undefined
);
const RDF = $rdf.Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#");
const targetSym = $rdf.sym(target);
const dcelement = {
typeUri: context.anyJS(targetSym, RDF("type")).value as string,
title: context.anyJS(targetSym, DCT("title")) as string,
description: context.anyJS(targetSym, DCT("description")) as string,
creator: context.anyJS(targetSym, DCT("creator")) as string,
date: context.anyJS(targetSym, DCT("date")) as string,
contentType: context.anyJS(targetSym, DCT("contentType")) as string
};
let result = document.createElement("div");
ReactDOM.render(<h1>{title.value}</h1>, result);
ReactDOM.render(
<>
<DublinCoreElementComponent dcelement={dcelement} />
</>,
result
);
return result;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment