Skip to content

Commit

Permalink
Added lessoncomponents addons
Browse files Browse the repository at this point in the history
  • Loading branch information
IyaadArshad committed Oct 28, 2023
1 parent 5349921 commit be505e9
Showing 1 changed file with 70 additions and 1 deletion.
71 changes: 70 additions & 1 deletion src/components/Lessons/LessonComponents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,75 @@ function InfoL({ lessonData }) {
);
}

function Reading({ lessonData }) {
const convertToHTML = (jsonContent) => {
if (!jsonContent) return null;

return jsonContent.blocks.map((block) => {
if (block.type === "header-one") {
return <h1 key={block.key}>{block.text}</h1>;
} else if (block.type === "header-two") {
return <h2 key={block.key}>{block.text}</h2>;
} else if (block.type === "header-three") {
return <h3 key={block.key}>{block.text}</h3>;
} else if (block.type === "atomic") {
if (block.data.type === "image") {
return <img key={block.key} src={block.data.src} alt={block.text} />;
}
} else {
let style = {};
if (block.inlineStyleRanges) {
block.inlineStyleRanges.forEach(range => {
if (range.style === "BOLD") {
style.fontWeight = "bold";
} else if (range.style === "UNDERLINE") {
style.textDecoration = "underline";
} else if (range.style === "ITALIC") {
style.fontStyle = "italic";
}
});
}

if (block.entityRanges && block.entityRanges.length > 0) {
// Assuming only one entity per block for simplicity
const entity = block.entityRanges[0];
if (entity.type === "LINK") {
return (
<a key={block.key} href={entity.data.url} style={style}>
{block.text}
</a>
);
}
}

if (block.type === "ordered-list-item") {
return <ol key={block.key}><li style={style}>{block.text}</li></ol>;
} else if (block.type === "unordered-list-item") {
return <ul key={block.key}><li style={style}>{block.text}</li></ul>;
} else {
return <p key={block.key} style={style}>{block.text}</p>;
}
}
});
};

if (!lessonData) {
return <div>Loading...</div>; // or some other loading indicator
}

const currentPageData = lessonData.lessonData.pagesData["1"];

const htmlContent = convertToHTML(currentPageData.data);

return (
<div className="container">
<div className="panel text-center align-items-center">
<div className="lessonContent">{htmlContent}</div>
</div>
</div>
);
}

function QuizL({}) {}

function ResultsL({}) {}
Expand All @@ -75,7 +144,7 @@ function LessonPlayer() {
<div>
<Navbar />
<FetchLessonDataL setLessonData={setLessonData} />
<InfoL lessonData={lessonData} />
<Reading lessonData={lessonData} />
</div>
);
}
Expand Down

0 comments on commit be505e9

Please sign in to comment.