-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Andi-IM/feature/only_me
implement fetch api from backend
- Loading branch information
Showing
1 changed file
with
89 additions
and
77 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,90 +1,102 @@ | ||
import { useNavigate } from "react-router-dom"; | ||
import {useNavigate} from "react-router-dom"; | ||
import getDocsPS from "../../helpers/getDocsPS"; | ||
import addDataPS from "../../helpers/addDataPS"; | ||
import { useState, useEffect, Fragment } from "react"; | ||
import deleteDataPS from "../../helpers/deleteDataPS"; | ||
import { Card, Col, Row, Space, Spin, Table, Typography } from "antd"; | ||
import {useEffect, useState} from "react"; | ||
import {Col, Row, Space, Spin, Table, Typography} from "antd"; | ||
import formatSecondsToDate from "../../helpers/formatSecondsToDate"; | ||
import CardData from "../../components/Dashboard/CardData"; | ||
|
||
const { Column } = Table; | ||
function Dashboard() { | ||
const navigate = useNavigate(); | ||
const [state, setState] = useState({ | ||
arrDatas: [], | ||
loading: false, | ||
}); | ||
const {Column} = Table; | ||
|
||
const getDataHandler = () => { | ||
getDocsPS({ | ||
collectionName: "history", | ||
})?.then((arrDatas) => { | ||
setState((prev) => ({ | ||
...prev, | ||
arrDatas, | ||
})); | ||
function Dashboard() { | ||
const navigate = useNavigate(); | ||
const [users, setUser] = useState(0) | ||
const [state, setState] = useState({ | ||
arrDatas: [], | ||
loading: false, | ||
}); | ||
}; | ||
|
||
// const addDataHandler = () => { | ||
// addDataPS({ | ||
// collectionName: "admin", | ||
// formData: { | ||
// administrator: false, | ||
// authProvider: "Email", | ||
// name: "Admin", | ||
// }, | ||
// })?.then((newData) => { | ||
// setState((prev) => ({ ...prev, arrDatas: newData })); | ||
// }); | ||
// }; | ||
const getDataHandler = () => { | ||
getDocsPS({ | ||
collectionName: "history", | ||
})?.then((arrDatas) => { | ||
setState((prev) => ({ | ||
...prev, | ||
arrDatas, | ||
})); | ||
}); | ||
}; | ||
|
||
const userCount = () => { | ||
fetch("https://orchid-app-7fe3d.et.r.appspot.com/users") | ||
.then(response => { | ||
if (response.ok){ | ||
response.json().then(data => { | ||
setUser(data.size) | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
// const addDataHandler = () => { | ||
// addDataPS({ | ||
// collectionName: "admin", | ||
// formData: { | ||
// administrator: false, | ||
// authProvider: "Email", | ||
// name: "Admin", | ||
// }, | ||
// })?.then((newData) => { | ||
// setState((prev) => ({ ...prev, arrDatas: newData })); | ||
// }); | ||
// }; | ||
|
||
// const deleteDataHandler = (id) => { | ||
// deleteDataPS({ | ||
// collectionName: "admin", | ||
// docId: id, | ||
// })?.then((newData) => { | ||
// setState((prev) => ({ ...prev, arrDatas: newData })); | ||
// }); | ||
// }; | ||
// const deleteDataHandler = (id) => { | ||
// deleteDataPS({ | ||
// collectionName: "admin", | ||
// docId: id, | ||
// })?.then((newData) => { | ||
// setState((prev) => ({ ...prev, arrDatas: newData })); | ||
// }); | ||
// }; | ||
|
||
useEffect(() => { | ||
getDataHandler(); | ||
}, []); | ||
useEffect(() => { | ||
getDataHandler(); | ||
userCount() | ||
}, []); | ||
|
||
return ( | ||
<Space direction="vertical" size="large"> | ||
<Row> | ||
<Col span={24}> | ||
<Typography.Title>Dashboard</Typography.Title> | ||
</Col> | ||
</Row> | ||
<Row gutter={[16, 16]}> | ||
<Col> | ||
<CardData cardName="Users" count={69} /> | ||
</Col> | ||
<Col> | ||
<CardData cardName="Detections" count={state?.arrDatas?.length} /> | ||
</Col> | ||
</Row> | ||
<Row> | ||
<Col span={24}> | ||
<Spin spinning={state?.loading}> | ||
<Table dataSource={state?.arrDatas} tableLayout="fixed"> | ||
<Column title="UID" dataIndex="UID" /> | ||
<Column title="Acc" dataIndex="Acc" /> | ||
<Column | ||
title="Date" | ||
dataIndex="Date" | ||
render={(date) => formatSecondsToDate(date?.seconds)} | ||
/> | ||
<Column title="Instance" dataIndex="Instance" /> | ||
</Table> | ||
</Spin> | ||
</Col> | ||
</Row> | ||
</Space> | ||
); | ||
return ( | ||
<Space direction="vertical" size="large"> | ||
<Row> | ||
<Col span={24}> | ||
<Typography.Title>Dashboard</Typography.Title> | ||
</Col> | ||
</Row> | ||
<Row gutter={[16, 16]}> | ||
<Col> | ||
<CardData cardName="Users" count={users}/> | ||
</Col> | ||
<Col> | ||
<CardData cardName="Detections" count={state?.arrDatas?.length}/> | ||
</Col> | ||
</Row> | ||
<Row> | ||
<Col span={24}> | ||
<Spin spinning={state?.loading}> | ||
<Table dataSource={state?.arrDatas} tableLayout="fixed"> | ||
<Column title="UID" dataIndex="UID"/> | ||
<Column title="Acc" dataIndex="Acc"/> | ||
<Column | ||
title="Date" | ||
dataIndex="Date" | ||
render={(date) => formatSecondsToDate(date?.seconds)} | ||
/> | ||
<Column title="Instance" dataIndex="Instance"/> | ||
</Table> | ||
</Spin> | ||
</Col> | ||
</Row> | ||
</Space> | ||
); | ||
} | ||
|
||
export default Dashboard; |