Skip to content

Commit

Permalink
Setup base route with base firebase call
Browse files Browse the repository at this point in the history
  • Loading branch information
nesmon committed Mar 21, 2023
1 parent cd03aab commit 525e966
Show file tree
Hide file tree
Showing 14 changed files with 1,823 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ dist-ssr
*.njsproj
*.sln
*.sw?

config.js
1,717 changes: 1,714 additions & 3 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"preview": "vite preview"
},
"dependencies": {
"firebase": "^9.18.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.9.0"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Link } from 'react-router-dom';
import { useParams } from 'react-router-dom';
import './Score.css';
import './ChartScore.css';

function Score() {
const { chartId } = useParams();
Expand Down
7 changes: 7 additions & 0 deletions src/Route/Charts/Charts.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.songList {
display: flex;
flex-direction: row;
justify-content: space-around;
padding: 10px;
margin: 0;
}
42 changes: 42 additions & 0 deletions src/Route/Charts/Charts.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { useEffect, useState } from 'react';
import { json, Link } from 'react-router-dom';
import './Charts.css';
import Chart from './../../Components/chart/chart';
import { getFirestore, collection, addDoc, getDocs } from "firebase/firestore";

function Charts() {
const [charts, setCharts] = useState([]);

const getCharts = async () => {
const db = getFirestore();
const chartRef = collection(db, "Chart");
const snapshot = await getDocs(chartRef);
const charts = snapshot.docs.map(doc => doc.data());

return charts;
}

useEffect(() => {
async function fetchData() {
const data = await getCharts();
setCharts(data);
}
fetchData();
}, []);

return (
<div className="App">
<div className="songList">
{charts.map((item, index) => {
return (
<Link to={`/score/${item.name}`} key={index}>
<Chart key={index} data={item} />
</Link>
)
})}
</div>
</div>
);
}

export default Charts;
7 changes: 0 additions & 7 deletions src/Route/Index/Index.css
Original file line number Diff line number Diff line change
@@ -1,7 +0,0 @@
.songList {
display: flex;
flex-direction: row;
justify-content: space-around;
padding: 10px;
margin: 0;
}
19 changes: 4 additions & 15 deletions src/Route/Index/Index.jsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import { Link } from 'react-router-dom';
import './Index.css';
import charts from './../../charts.json';
import Chart from './../../Components/chart/chart';

function App() {
function Index() {
return (
<div className="App">
<div className="songList">
{charts.map((item, index) => {
return (
<Link to={`/score/${item.name}`} key={index}>
<Chart key={index} data={item} />
</Link>
)
})}
</div>
</div>
<p>Hello world</p>
</div>
);
}

export default App;
export default Index;
Empty file added src/Route/NotFound/NotFound.css
Empty file.
11 changes: 11 additions & 0 deletions src/Route/NotFound/NotFound.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import './NotFound.css';

function NotFound() {
return (
<div className="App">
<p>404</p>
</div>
);
}

export default NotFound;
13 changes: 13 additions & 0 deletions src/config.example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const config = {
firebase: {
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
}
}

export default config
14 changes: 12 additions & 2 deletions src/main.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
// React
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';

// Router
import {
createBrowserRouter,
RouterProvider
} from "react-router-dom";
import Router from './router.jsx';

const router = createBrowserRouter(Router);

// Firebase
import { initializeApp } from "firebase/app";
import Config from './config.js';

const firebaseConfig = Config.firebase;
const app = initializeApp(firebaseConfig);


const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<RouterProvider router={router} />
</React.StrictMode>
);
);
22 changes: 16 additions & 6 deletions src/router.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import App from './Route/Index/Index';
import Score from './Route/Score/Score';
import Index from './Route/Index/Index';
import Charts from './Route/Charts/Charts';
import ChartScore from './Route/ChartScore/ChartScore';
import NotFound from './Route/NotFound/NotFound';

const router = [
{
path: "/",
element: <App />,
element: <Index />,
},
{
path: "/score/:chartId",
element: <Score />,
}
path: "/charts",
element: <Charts />,
},
{
path: "/charts/:chartId",
element: <ChartScore />,
},
{
path: "*",
element: <NotFound />,
},
]

export default router;

0 comments on commit 525e966

Please sign in to comment.