-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(page) : component-ize lecture room page(#47)
- Loading branch information
Showing
15 changed files
with
318 additions
and
111 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import React , {useEffect, useState} from "react"; | ||
import { useAtom } from "jotai"; | ||
import { LanguageChangeAtom } from "util/atom"; | ||
import { toast } from 'react-toastify'; | ||
|
||
import * as Styled from "styles/ComponentStyles"; | ||
import * as Component from "components/Components"; | ||
import ModularRequest from "util/ModularRequest"; | ||
|
||
import right from "img/right.png"; | ||
import left from "img/left.png"; | ||
|
||
function RecentLectures(props){ | ||
const [LanguageChange,setLanguageChange] = useAtom(LanguageChangeAtom); | ||
const notify = (content)=> toast(content); | ||
|
||
const grade = props.grade; | ||
|
||
const [recentLectures, setRecentLectures] = useState([]); | ||
const [isLoaded, setIsLoaded] = useState(false); | ||
let [page, setPage] = useState(1); | ||
const [isEmpty, setIsEmpty] = useState(true); | ||
|
||
const total = (Math.floor((recentLectures.length-1)/4)+1); | ||
|
||
var RecentVideos="Recent Videos"; | ||
var emptyRecent = "there is no empty lecture to show."; | ||
if (LanguageChange===0){ | ||
RecentVideos="Recent Videos"; | ||
emptyRecent = "there is no empty lecture to show."; | ||
} | ||
else if(LanguageChange===1){ | ||
RecentVideos="최근 올라온 강의"; | ||
emptyRecent="최근 강의가 없습니다"; | ||
} | ||
|
||
useEffect(()=>{ | ||
try{ | ||
let m2 = new ModularRequest({ | ||
"path" : `course/recent?grade=${grade}&number=16`, | ||
"method" : "get", | ||
"headers" : { | ||
"Authorization" : `Bearer ${localStorage.getItem('login-token')}`, | ||
"Content-Type": 'application/json', | ||
} | ||
}); | ||
|
||
m2.send().then((res)=>{ | ||
if(res.status=== 200) { | ||
setRecentLectures(res.data.details); | ||
setIsLoaded(true); | ||
setIsEmpty(false); | ||
} else { | ||
setIsEmpty(true); | ||
setIsLoaded(true); | ||
} | ||
} | ||
); | ||
} catch (e) { | ||
setRecentLectures([]); | ||
console.log("error in reading trendings"); | ||
} | ||
},[grade]); | ||
|
||
function handlePageShiftClick(toLeft){ | ||
if(toLeft){ if(page>1) setPage(--page);} | ||
else { if(page<total) setPage(++page);} | ||
} | ||
|
||
|
||
|
||
return ( | ||
<> | ||
<Styled.UnderlinedTitle>{RecentVideos}</Styled.UnderlinedTitle> | ||
{isLoaded &&((isEmpty)?<Styled.EmptyBox width="100%">{emptyRecent}</Styled.EmptyBox>:<> | ||
<Styled.LectureGroupScrollWrapper> | ||
<Styled.LectureGroup offset={-page+1}> | ||
{recentLectures.map((dat)=><Component.LectureBox key={dat.course_id} src={dat} width="calc(40vw - 5px)"></Component.LectureBox>)} | ||
</Styled.LectureGroup> | ||
</Styled.LectureGroupScrollWrapper> | ||
|
||
<Styled.Buttongroup> | ||
<img alt="left" src={left} onClick={()=>{handlePageShiftClick(true);}}/> | ||
<span>{page}/{total}</span> | ||
<img alt="right" src={right} onClick={()=>{handlePageShiftClick(false);}}/> | ||
</Styled.Buttongroup> | ||
</> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
export default RecentLectures; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React , {useEffect, useState} from "react"; | ||
import { useAtom } from "jotai"; | ||
import { LanguageChangeAtom } from "util/atom"; | ||
import { toast } from 'react-toastify'; | ||
|
||
import * as Styled from "styles/ComponentStyles"; | ||
import * as Component from "components/Components"; | ||
import ModularRequest from "util/ModularRequest"; | ||
|
||
|
||
function TrendingLecture(props){ | ||
const [LanguageChange,setLanguageChange] = useAtom(LanguageChangeAtom); | ||
const [trending, setTrending] = useState({}); | ||
const [isEmpty, setIsEmpty] = useState(true); | ||
const notify = (content)=> toast(content); | ||
|
||
var bestLecture="Best Lecture"; | ||
var emptyTrending="there is no trending lecture to show."; | ||
|
||
if (LanguageChange===0){ | ||
bestLecture="Trending Lecture"; | ||
emptyTrending="there is no trending lecture to show."; | ||
} | ||
else if(LanguageChange===1){ | ||
bestLecture="추천수 높은 강의"; | ||
emptyTrending = "추천수 높은 강의가 없습니다."; | ||
}; | ||
|
||
const grade = props.grade; | ||
|
||
|
||
|
||
useEffect(()=>{ | ||
try { | ||
let m1 = new ModularRequest({ | ||
"path" : `course/trending?grade=${grade}`, | ||
"method" : "get", | ||
"headers" : { | ||
"Authorization" : `Bearer ${localStorage.getItem('login-token')}`, | ||
"Content-Type": 'application/json', | ||
} | ||
}); | ||
|
||
m1.send().then((res)=>{ | ||
if(res.status=== 200) { | ||
setIsEmpty(false); | ||
setTrending(res.data.details); | ||
} | ||
} | ||
); | ||
|
||
} catch (e) { | ||
setTrending({}); | ||
console.log("error in reading trendings"); | ||
console.error(e.message); | ||
} | ||
},[]); | ||
|
||
|
||
|
||
return ( | ||
<> | ||
<Styled.UnderlinedTitle align="center">{bestLecture}</Styled.UnderlinedTitle> | ||
{(!isEmpty)?<Component.LectureBox src={trending}></Component.LectureBox>:<Styled.EmptyBox width="100%">{emptyTrending}</Styled.EmptyBox>} | ||
</> | ||
); | ||
} | ||
|
||
export default TrendingLecture; | ||
|
Oops, something went wrong.