Skip to content

Commit

Permalink
topics added
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakibhasaniu committed Oct 11, 2022
1 parent 9a3d55a commit 0e5021d
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 16 deletions.
14 changes: 9 additions & 5 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import { createBrowserRouter, RouterProvider } from 'react-router-dom';
import Main from './layout/Main';
import Home from './components/Home/Home'
import Topics from './components/Topics/Topics'
import Statictics from './components/Statistics/Statictics';
import Statictics from './components/Statictics/Statictics';
import Question from './components/Question/Question';
import ErrorPage from './components/ErrorPage/Errorpage';

const router = createBrowserRouter([
{
path:'/',
errorElement: <ErrorPage></ErrorPage>,
loader: () => fetch('https://openapi.programming-hero.com/api/quiz'),
element:<Main></Main>,
children: [
{
Expand All @@ -20,17 +23,18 @@ const router = createBrowserRouter([
path:'/home',
element: <Home></Home>
},
{
path:'/topics',
element: <Topics></Topics>
},
{
path:'/statictics',
element: <Statictics></Statictics>
},
{
path:'/question',
element: <Question></Question>
},
{
path:'/quiz/:id',
loader: async({params}) => fetch(`https://openapi.programming-hero.com/api/quiz/${params.id}`),
element: <Topics></Topics>
}
]
},
Expand Down
24 changes: 24 additions & 0 deletions src/components/Display/Display.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { Link } from 'react-router-dom';

const Display = ({quiz}) => {
// console.log(quiz);
const {id,name,logo,total} = quiz;
return (
<div>
<img
className='bg-slate-900 '
src={logo}
alt=''
/>
<p className='mb-2 text-xl font-bold leading-none sm:text-2xl'>{name}</p>
<Link to={`/quiz/${id}`}><button
>
Start Quiz
</button></Link>

</div>
);
};

export default Display;
16 changes: 13 additions & 3 deletions src/components/Home/Home.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import React from 'react';

import React, { useContext } from 'react';
import { DataContext } from '../../layout/Main';
import Display from '../Display/Display';

const Home = () => {

const datas= useContext(DataContext);
const dt = datas.data
// console.log(dt);


return (
<div>
<h2>This Is Home Area</h2>
{
dt.map(quiz => <Display key={quiz.id} quiz={quiz}></Display> )
}
</div>
);
};
Expand Down
9 changes: 7 additions & 2 deletions src/components/Navbar/Navbar.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import React from 'react';
import { Link } from 'react-router-dom';

const Navbar = () => {
return (
<div>
<h2>This is Navbar</h2>
<div className='text-center p-8'>
<Link className='mr-4' to='/home'> Home</Link>
<Link className='mr-4' to='/topics'>Quiz</Link>
<Link className='mr-4' to='/statictics'>Chart</Link>
<Link className='mr-4' to='/question'>Question</Link>

</div>
);
};
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions src/components/Topics/Topics.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React from 'react';
import { useLoaderData } from 'react-router-dom';

const Topics = () => {

const allData = useLoaderData();
const {data} = allData;
// const quiz = data.question
console.log(data);
return (
<div>
<h2>This is Quiz Area</h2>
Expand Down
18 changes: 12 additions & 6 deletions src/layout/Main.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import React from 'react';
import { Outlet } from 'react-router-dom';
import Footer from '../components/Footer/Footer';
import React, { createContext } from 'react';
import { Outlet, useLoaderData } from 'react-router-dom';

import Navbar from '../components/Navbar/Navbar';


export const DataContext = createContext([])
const Main = () => {
const datas = useLoaderData();
// console.log(datas);

// const{data} = datas;

return (
<div>
<DataContext.Provider value={datas}>
<Navbar></Navbar>
<Outlet></Outlet>
<Footer></Footer>
</div>
</DataContext.Provider>
);
};

Expand Down

0 comments on commit 0e5021d

Please sign in to comment.