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

View File

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