Skip to content

Commit

Permalink
fix homepagelist #160
Browse files Browse the repository at this point in the history
  • Loading branch information
itIsJim committed May 8, 2023
1 parent c92236f commit 48419e8
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions client/src/pages/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import isLabelEnd from "katex/dist/katex.mjs";
import { GlobalStateContext } from "../GlobalStateProvider";

function Home() {
const { myCoursesNewQuestions, MyReplies, MyQuestions, MyAnswers } =
const { userID, MyReplies, MyQuestions, MyAnswers } =
useContext(GlobalStateContext);

const [myCourseNewQuestions, setMyCourseNewQuestions] = useState([])

const homePageList = [
//!! typeof(rows) = Array() !!//
{
scope: "default",
title: "New questions in courses enrolled",
rows: myCoursesNewQuestions,
rows: myCourseNewQuestions,
},
{
scope: "default",
Expand Down Expand Up @@ -54,7 +56,40 @@ function Home() {

const [homeLists, setHomeLists] = useState(homePageList);

console.log(myCoursesNewQuestions);
function homeCardListingTruncate (htmlText) {

const strTruncate = (str) => {
let arr = str.split(" ").slice(0, 5);
return arr.join(" ") + "..."
}

let span = document.createElement('span');
span.innerHTML = htmlText;
return strTruncate(span.textContent) || strTruncate(span.innerText);
}


// first render
useEffect(()=>{
// five items per page in Home page
API.getMyCourseNewQuestions(userID, 5).then((questions) => {
setMyCourseNewQuestions(questions.map((x) => [homeCardListingTruncate(x.questiontext.text)]));
});
}, [])


useEffect(()=> {
setHomeLists(
[
{
scope: "default",
title: "New questions in courses enrolled",
rows: myCourseNewQuestions,
},
...homePageList.slice(1)
]
)
}, [myCourseNewQuestions])

return (
<>
Expand Down

0 comments on commit 48419e8

Please sign in to comment.