Added stats & SQL order by on get points

This commit is contained in:
2024-10-16 09:35:52 +02:00
parent 8bde354b71
commit 60a7570ca2
7 changed files with 137 additions and 7 deletions
+27
View File
@@ -8,6 +8,12 @@ import { useEffect, useState } from 'react';
export const useData = () => {
const [userData, setUserData] = useState(null);
const [stats, setStats] = useState({
year: '00',
month: '00',
week: '00',
total: '00',
});
useEffect(() => {
(async () => {
@@ -31,9 +37,30 @@ export const useData = () => {
setUserData(formattedResponse);
})();
(async () => {
const token = localStorage.getItem('token');
const request = await fetch('/api/stats', {
method: 'GET',
headers: {
Authorization: token,
},
});
const response = await request.json();
setStats({
year: `${response.year}`.padStart(2, '0'),
month: `${response.month}`.padStart(2, '0'),
week: `${response.week}`.padStart(2, '0'),
total: `${response.total}`.padStart(2, '0'),
});
})();
}, []);
return {
userData,
stats,
};
};