Fixed code formatting and removed unused imports in Dashboard component.

This commit is contained in:
Resh 2024-12-11 00:09:58 +07:00
parent faccef8205
commit efc47e9c53
3 changed files with 200 additions and 134 deletions

View File

@ -1,14 +1,10 @@
import axiosInstance from '../../../../utils/axiosInstance'; import axiosInstance from '../../../../utils/axiosInstance'
const fetchJourney = async () => { const fetchJourney = async () => {
try { const response = await axiosInstance.get(`/topic/complete`)
const response = await axiosInstance.get(`/topic/complete`); return response.data
return response.data; }
} catch (error) {
throw error;
}
};
export default { export default {
fetchJourney, fetchJourney,
}; }

View File

@ -1,100 +1,170 @@
import React from 'react'; import { Container, Row, Col, Card, Button, ProgressBar } from 'react-bootstrap'
import { Container, Row, Col, Card, Button, ProgressBar } from 'react-bootstrap'; import newBie from '../../../../assets/images/illustration/emptyJourney.png'
import newBie from '../../../../assets/images/illustration/emptyJourney.png'; import { Link, NavLink } from 'react-router-dom'
import reading from '../../../../assets/images/illustration/reading.png'; import useDashboards from '../hooks/useDashboards'
import listening from '../../../../assets/images/illustration/listening.png'; import { slugify } from '../../../../utils/Constant'
import { Link, NavLink } from 'react-router-dom'; import Skeleton from 'react-loading-skeleton'
import useDashboards from '../hooks/useDashboards';
import { slugify } from '../../../../utils/Constant';
import Skeleton from 'react-loading-skeleton';
function validName(fullName) { function validName(fullName) {
const nameArray = fullName.split(" "); const nameArray = fullName.split(' ')
const firstTwoWords = nameArray.slice(0, 2).join(" "); const firstTwoWords = nameArray.slice(0, 2).join(' ')
return firstTwoWords; return firstTwoWords
} }
const Dashboard = () => { const Dashboard = () => {
const { username } = JSON.parse(localStorage.getItem('userData')); const { username } = JSON.parse(localStorage.getItem('userData'))
const { journey, loading, error, thumbPath} = useDashboards(); const { journey, loading, error, thumbPath } = useDashboards()
const noData = () =>{ return journey.lenght > 0 ? false : true }; const noData = () => {
return journey.lenght == 0
}
if (error) { if (error) {
return <div>Error: {error.message}</div>; return <div>Error: {error.message}</div>
} }
return ( return (
<div className='home-page'> <div className="home-page">
<h1 className='text-blue text-capitalize fw-bold mb-1'>Hi, {validName(username)} !</h1> <h1 className="text-blue text-capitalize fw-bold mb-1">
<p className='text-secondary'>Lets evolve together with adaptive learning tailored just for you.</p> Hi, {validName(username)} !
<h4 className='text-blue mt-4 fw-bold'>Your Last Journey!</h4> </h1>
<Container fluid className='bg-white rounded rounded-4 p-4'> <p className="text-secondary">
<Row xs={1} className='filled-journey'> Lets evolve together with adaptive learning tailored just for you.
<Col className='mb-3'> </p>
{loading ?( <h4 className="text-blue mt-4 fw-bold">Your Last Journey!</h4>
<Container fluid className="bg-white rounded rounded-4 p-4">
<Row xs={1} className="filled-journey">
<Col className="mb-3">
{loading ? (
<> <>
<Card className='flex-row p-3 mb-3 border-0 shadow shadow-sm rounded-4'> <Card className="flex-row p-3 mb-3 border-0 shadow shadow-sm rounded-4">
<div className="w-100 d-flex"> <div className="w-100 d-flex">
<Skeleton containerClassName="mb-2" className='mb-2 rounded-4' style={{width:"10vw", height:"10vw"}} /> <Skeleton
<div className='ps-2 d-flex flex-column justify-content-between'> containerClassName="mb-2"
<Skeleton containerClassName="mb-2" className='mb-2 rounded-4' style={{width:"20vw", height:"3vw"}} /> className="mb-2 rounded-4"
<Skeleton containerClassName="mb-2" className='mb-2 rounded-4' style={{width:"30vw", height:"2vw"}} /> style={{ width: '10vw', height: '10vw' }}
/>
<div className="ps-2 d-flex flex-column justify-content-between">
<Skeleton
containerClassName="mb-2"
className="mb-2 rounded-4"
style={{ width: '20vw', height: '3vw' }}
/>
<Skeleton
containerClassName="mb-2"
className="mb-2 rounded-4"
style={{ width: '30vw', height: '2vw' }}
/>
</div> </div>
<Skeleton containerClassName="mb-2 mt-auto ms-auto" className='mb-2 rounded-4' style={{width:"17vw", height:"4vw"}} /> <Skeleton
containerClassName="mb-2 mt-auto ms-auto"
className="mb-2 rounded-4"
style={{ width: '17vw', height: '4vw' }}
/>
</div> </div>
</Card> </Card>
<Card className='flex-row p-3 mb-3 border-0 shadow shadow-sm rounded-4'> <Card className="flex-row p-3 mb-3 border-0 shadow shadow-sm rounded-4">
<div className="w-100 d-flex"> <div className="w-100 d-flex">
<Skeleton containerClassName="mb-2" className='mb-2 rounded-4' style={{width:"10vw", height:"10vw"}} /> <Skeleton
<div className='ps-2 d-flex flex-column justify-content-between'> containerClassName="mb-2"
<Skeleton containerClassName="mb-2" className='mb-2 rounded-4' style={{width:"20vw", height:"3vw"}} /> className="mb-2 rounded-4"
<Skeleton containerClassName="mb-2" className='mb-2 rounded-4' style={{width:"30vw", height:"2vw"}} /> style={{ width: '10vw', height: '10vw' }}
/>
<div className="ps-2 d-flex flex-column justify-content-between">
<Skeleton
containerClassName="mb-2"
className="mb-2 rounded-4"
style={{ width: '20vw', height: '3vw' }}
/>
<Skeleton
containerClassName="mb-2"
className="mb-2 rounded-4"
style={{ width: '30vw', height: '2vw' }}
/>
</div> </div>
<Skeleton containerClassName="mb-2 mt-auto ms-auto" className='mb-2 rounded-4' style={{width:"17vw", height:"4vw"}} /> <Skeleton
containerClassName="mb-2 mt-auto ms-auto"
className="mb-2 rounded-4"
style={{ width: '17vw', height: '4vw' }}
/>
</div> </div>
</Card> </Card>
</> </>
) : ( ) : noData() ? (
noData() ?( <Col className="d-flex flex-column items-center">
<Col className='d-flex flex-column items-center'> <h4 className="mb-0">Still new?</h4>
<h4 className='mb-0'>Still new?</h4> <p className="fs-5 text-muted fw-light">Begin your journey!</p>
<p className='fs-5 text-muted fw-light'>Begin your journey!</p>
<img src={newBie} alt="" /> <img src={newBie} alt="" />
<Button as={Link} to={'/learning/module'} variant='warning' className='mt-4 py-2 px-5 rounded-35'>Explore</Button> <Button
as={Link}
to={'/learning/module'}
variant="warning"
className="mt-4 py-2 px-5 rounded-35"
>
Explore
</Button>
</Col> </Col>
):( ) : (
journey.map(data => ( journey.map(data => (
<Card className='flex-row p-3 mb-3 border-0 shadow shadow-sm rounded-4'> <Card
<Card.Img variant="top" src={`${thumbPath}${data.THUMBNAIL}`} className='ratio ratio-1x1 rounded rounded-3 me-3' /> key={data.ID}
<Card.Body className='p-0 d-flex flex-column justify-content-between'> className="flex-row p-3 mb-3 border-0 shadow shadow-sm rounded-4"
<div className='w-75'> >
<Card.Img
variant="top"
src={
data.THUMBNAIL ? `${thumbPath}${data.THUMBNAIL}` : newBie
}
className="ratio ratio-1x1 rounded rounded-3 me-3"
/>
<Card.Body className="p-0 d-flex flex-column justify-content-between">
<div className="w-75">
<Card.Title>{data.NAME_SECTION}</Card.Title> <Card.Title>{data.NAME_SECTION}</Card.Title>
<Card.Text className='text-muted'> <Card.Text className="text-muted">
{data.DESCRIPTION_SECTION} {data.DESCRIPTION_SECTION}
</Card.Text> </Card.Text>
</div> </div>
<div className="w-100 d-flex align-items-end"> <div className="w-100 d-flex align-items-end">
<div className="w-75"> <div className="w-75">
<div className='d-flex align-items-center'> <div className="d-flex align-items-center">
<ProgressBar now={((data.COMPLETED_TOPICS / data.TOTAL_TOPICS)*100).toFixed(0)} className='w-75' /> <ProgressBar
<span className='text-blue ms-2'>{((data.COMPLETED_TOPICS / data.TOTAL_TOPICS)*100).toFixed(0)}%</span> now={(
(data.COMPLETED_TOPICS / data.TOTAL_TOPICS) *
100
).toFixed(0)}
className="w-75"
/>
<span className="text-blue ms-2">
{(
(data.COMPLETED_TOPICS / data.TOTAL_TOPICS) *
100
).toFixed(0)}
%
</span>
</div> </div>
<p className='text-muted m-0'>{data.COMPLETED_TOPICS} / {data.TOTAL_TOPICS} Topics</p> <p className="text-muted m-0">
{data.COMPLETED_TOPICS} / {data.TOTAL_TOPICS} Topics
</p>
</div> </div>
<Button as={NavLink} to={`/learning/module/${slugify(data.NAME_SECTION)}`} variant="warning" className='ms-auto py-2 px-5 rounded-35'>Continue</Button> <Button
as={NavLink}
to={`/learning/module/${slugify(data.NAME_SECTION)}`}
variant="warning"
className="ms-auto py-2 px-5 rounded-35"
>
Continue
</Button>
</div> </div>
</Card.Body> </Card.Body>
</Card> </Card>
)) ))
)
)} )}
</Col> </Col>
</Row> </Row>
</Container> </Container>
</div> </div>
); )
}; }
export default Dashboard; export default Dashboard

View File

@ -1,13 +1,13 @@
export const API_URL = 'http://54.173.167.62/api'; export const API_URL = 'https://z30xrgl5-3001.asse.devtunnels.ms/api'
export const MEDIA_URL = 'http://54.173.167.62/api/uploads'; export const MEDIA_URL = 'https://z30xrgl5-3001.asse.devtunnels.ms/api/uploads'
export let headerSection = 'section'; export let headerSection = 'section'
export let headerTopic = 'topic'; export let headerTopic = 'topic'
export let headerLevel = 'level'; export let headerLevel = 'level'
export const slugify = (text) => { export const slugify = text => {
if (!text) { if (!text) {
return ''; return ''
} }
return text return text
@ -15,24 +15,24 @@ export const slugify = (text) => {
.toLowerCase() .toLowerCase()
.trim() .trim()
.replace(/\s+/g, '-') .replace(/\s+/g, '-')
.replace(/[^\w\-]+/g, '') .replace(/[^\w-]+/g, '')
.replace(/\-\-+/g, '-'); .replace(/--+/g, '-')
}; }
export const unSlugify = (text) => { export const unSlugify = text => {
if (!text) { if (!text) {
return ''; return ''
} }
return text return text
.toString() .toString()
.toLowerCase() .toLowerCase()
.replace(/-/g, ' ') .replace(/-/g, ' ')
.replace(/\b\w/g, (char) => char.toUpperCase()); .replace(/\b\w/g, char => char.toUpperCase())
}; }
export const setReviewHeader = (section, topic, level) => { export const setReviewHeader = (section, topic, level) => {
headerSection = section; headerSection = section
headerTopic = topic; headerTopic = topic
headerLevel = level; headerLevel = level
} }