Skip to content

Commit

Permalink
Merge pull request #7 from Andi-IM/feature/only_me
Browse files Browse the repository at this point in the history
implement fetch api from backend
  • Loading branch information
Andi-IM authored Sep 10, 2023
2 parents 11e3886 + bdd7a72 commit e9af6a2
Showing 1 changed file with 89 additions and 77 deletions.
166 changes: 89 additions & 77 deletions src/page/Dashboard/Dashboard.jsx
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;

0 comments on commit e9af6a2

Please sign in to comment.