diff --git a/public/locales/en-UK/translation.json b/public/locales/en-UK/translation.json
index bcfa271..a425ed4 100644
--- a/public/locales/en-UK/translation.json
+++ b/public/locales/en-UK/translation.json
@@ -51,6 +51,8 @@
"LAST_24_HRS": "Last 24 Hours",
"LAST_7_DAYS": "Last 7 Days",
"LAST_30_DAYS": "Last 30 Days",
+ "LAST_180_DAYS": "Last 180 Days",
+ "LAST_365_DAYS": "Last 365 Days",
"ALL_TIME": "All Time",
"ITEM_STATS": "Item Stats"
},
diff --git a/public/locales/fr-FR/translation.json b/public/locales/fr-FR/translation.json
index 6cb60d7..8660843 100644
--- a/public/locales/fr-FR/translation.json
+++ b/public/locales/fr-FR/translation.json
@@ -51,6 +51,8 @@
"LAST_24_HRS": "24 dernières heures",
"LAST_7_DAYS": "7 derniers jours",
"LAST_30_DAYS": "30 derniers jours",
+ "LAST_180_DAYS": "180 derniers jours",
+ "LAST_365_DAYS": "365 derniers jours",
"ALL_TIME": "Tout le temps",
"ITEM_STATS": "Statistiques du média"
},
diff --git a/src/pages/components/item-info/globalStats.jsx b/src/pages/components/item-info/globalStats.jsx
index 8a0667c..3034928 100644
--- a/src/pages/components/item-info/globalStats.jsx
+++ b/src/pages/components/item-info/globalStats.jsx
@@ -9,55 +9,40 @@ function GlobalStats(props) {
const [dayStats, setDayStats] = useState({});
const [weekStats, setWeekStats] = useState({});
const [monthStats, setMonthStats] = useState({});
+ const [d180Stats, setd180Stats] = useState({});
+ const [d365Stats, setd365Stats] = useState({});
const [allStats, setAllStats] = useState({});
- const token = localStorage.getItem('token');
+ const token = localStorage.getItem("token");
+
+ function fetchStats(hours = 24, setMethod = setDayStats) {
+ axios
+ .post(
+ `/stats/getGlobalItemStats`,
+ {
+ hours: hours,
+ itemid: props.ItemId,
+ },
+ {
+ headers: {
+ Authorization: `Bearer ${token}`,
+ "Content-Type": "application/json",
+ },
+ }
+ )
+ .then((dayData) => {
+ setMethod(dayData.data);
+ });
+ }
useEffect(() => {
const fetchData = async () => {
try {
- const dayData = await axios.post(`/stats/getGlobalItemStats`, {
- hours: (24*1),
- itemid: props.ItemId,
- }, {
- headers: {
- Authorization: `Bearer ${token}`,
- "Content-Type": "application/json",
- },
- });
- setDayStats(dayData.data);
-
- const weekData = await axios.post(`/stats/getGlobalItemStats`, {
- hours: (24*7),
- itemid: props.ItemId,
- }, {
- headers: {
- Authorization: `Bearer ${token}`,
- "Content-Type": "application/json",
- },
- });
- setWeekStats(weekData.data);
-
- const monthData = await axios.post(`/stats/getGlobalItemStats`, {
- hours: (24*30),
- itemid: props.ItemId,
- }, {
- headers: {
- Authorization: `Bearer ${token}`,
- "Content-Type": "application/json",
- },
- });
- setMonthStats(monthData.data);
-
- const allData = await axios.post(`/stats/getGlobalItemStats`, {
- hours: (24*999),
- itemid: props.ItemId,
- }, {
- headers: {
- Authorization: `Bearer ${token}`,
- "Content-Type": "application/json",
- },
- });
- setAllStats(allData.data);
+ fetchStats(24, setDayStats);
+ fetchStats(24 * 7, setWeekStats);
+ fetchStats(24 * 30, setMonthStats);
+ fetchStats(24 * 180, setd180Stats);
+ fetchStats(24 * 365, setd365Stats);
+ fetchStats(24 * 999, setAllStats);
} catch (error) {
console.log(error);
}
@@ -66,17 +51,20 @@ function GlobalStats(props) {
fetchData();
const intervalId = setInterval(fetchData, 60000 * 5);
return () => clearInterval(intervalId);
- }, [props.ItemId,token]);
-
+ }, [props.ItemId, token]);
return (
-
-
-
} />
-
} />
-
} />
-
} />
+
+
+
+
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
);
diff --git a/src/pages/components/library/library-stats.jsx b/src/pages/components/library/library-stats.jsx
index 7b73be6..dcd1ee5 100644
--- a/src/pages/components/library/library-stats.jsx
+++ b/src/pages/components/library/library-stats.jsx
@@ -9,55 +9,40 @@ function LibraryGlobalStats(props) {
const [dayStats, setDayStats] = useState({});
const [weekStats, setWeekStats] = useState({});
const [monthStats, setMonthStats] = useState({});
+ const [d180Stats, setd180Stats] = useState({});
+ const [d365Stats, setd365Stats] = useState({});
const [allStats, setAllStats] = useState({});
- const token = localStorage.getItem('token');
+ const token = localStorage.getItem("token");
+
+ function fetchStats(hours = 24, setMethod = setDayStats) {
+ axios
+ .post(
+ `/stats/getGlobalLibraryStats`,
+ {
+ hours: hours,
+ libraryid: props.LibraryId,
+ },
+ {
+ headers: {
+ Authorization: `Bearer ${token}`,
+ "Content-Type": "application/json",
+ },
+ }
+ )
+ .then((dayData) => {
+ setMethod(dayData.data);
+ });
+ }
useEffect(() => {
const fetchData = async () => {
try {
- const dayData = await axios.post(`/stats/getGlobalLibraryStats`, {
- hours: (24*1),
- libraryid: props.LibraryId,
- }, {
- headers: {
- Authorization: `Bearer ${token}`,
- "Content-Type": "application/json",
- },
- });
- setDayStats(dayData.data);
-
- const weekData = await axios.post(`/stats/getGlobalLibraryStats`, {
- hours: (24*7),
- libraryid: props.LibraryId,
- }, {
- headers: {
- Authorization: `Bearer ${token}`,
- "Content-Type": "application/json",
- },
- });
- setWeekStats(weekData.data);
-
- const monthData = await axios.post(`/stats/getGlobalLibraryStats`, {
- hours: (24*30),
- libraryid: props.LibraryId,
- }, {
- headers: {
- Authorization: `Bearer ${token}`,
- "Content-Type": "application/json",
- },
- });
- setMonthStats(monthData.data);
-
- const allData = await axios.post(`/stats/getGlobalLibraryStats`, {
- hours: (24*999),
- libraryid: props.LibraryId,
- }, {
- headers: {
- Authorization: `Bearer ${token}`,
- "Content-Type": "application/json",
- },
- });
- setAllStats(allData.data);
+ fetchStats(24, setDayStats);
+ fetchStats(24 * 7, setWeekStats);
+ fetchStats(24 * 30, setMonthStats);
+ fetchStats(24 * 180, setd180Stats);
+ fetchStats(24 * 365, setd365Stats);
+ fetchStats(24 * 999, setAllStats);
} catch (error) {
console.log(error);
}
@@ -66,16 +51,20 @@ function LibraryGlobalStats(props) {
fetchData();
const intervalId = setInterval(fetchData, 60000 * 5);
return () => clearInterval(intervalId);
- }, [props.LibraryId,token]);
+ }, [props.LibraryId, token]);
return (
-
-
-
} />
-
} />
-
} />
-
} />
+
+
+
+
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
);
diff --git a/src/pages/components/user-info/globalStats.jsx b/src/pages/components/user-info/globalStats.jsx
index ff65d96..3e06cbe 100644
--- a/src/pages/components/user-info/globalStats.jsx
+++ b/src/pages/components/user-info/globalStats.jsx
@@ -9,55 +9,40 @@ function GlobalStats(props) {
const [dayStats, setDayStats] = useState({});
const [weekStats, setWeekStats] = useState({});
const [monthStats, setMonthStats] = useState({});
+ const [d180Stats, setd180Stats] = useState({});
+ const [d365Stats, setd365Stats] = useState({});
const [allStats, setAllStats] = useState({});
- const token = localStorage.getItem('token');
+ const token = localStorage.getItem("token");
+
+ function fetchStats(hours = 24, setMethod = setDayStats) {
+ axios
+ .post(
+ `/stats/getGlobalUserStats`,
+ {
+ hours: hours,
+ userid: props.UserId,
+ },
+ {
+ headers: {
+ Authorization: `Bearer ${token}`,
+ "Content-Type": "application/json",
+ },
+ }
+ )
+ .then((dayData) => {
+ setMethod(dayData.data);
+ });
+ }
useEffect(() => {
const fetchData = async () => {
try {
- const dayData = await axios.post(`/stats/getGlobalUserStats`, {
- hours: (24*1),
- userid: props.UserId,
- }, {
- headers: {
- Authorization: `Bearer ${token}`,
- "Content-Type": "application/json",
- },
- });
- setDayStats(dayData.data);
-
- const weekData = await axios.post(`/stats/getGlobalUserStats`, {
- hours: (24*7),
- userid: props.UserId,
- }, {
- headers: {
- Authorization: `Bearer ${token}`,
- "Content-Type": "application/json",
- },
- });
- setWeekStats(weekData.data);
-
- const monthData = await axios.post(`/stats/getGlobalUserStats`, {
- hours: (24*30),
- userid: props.UserId,
- }, {
- headers: {
- Authorization: `Bearer ${token}`,
- "Content-Type": "application/json",
- },
- });
- setMonthStats(monthData.data);
-
- const allData = await axios.post(`/stats/getGlobalUserStats`, {
- hours: (24*999),
- userid: props.UserId,
- }, {
- headers: {
- Authorization: `Bearer ${token}`,
- "Content-Type": "application/json",
- },
- });
- setAllStats(allData.data);
+ fetchStats(24, setDayStats);
+ fetchStats(24 * 7, setWeekStats);
+ fetchStats(24 * 30, setMonthStats);
+ fetchStats(24 * 180, setd180Stats);
+ fetchStats(24 * 365, setd365Stats);
+ fetchStats(24 * 999, setAllStats);
} catch (error) {
console.log(error);
}
@@ -66,16 +51,20 @@ function GlobalStats(props) {
fetchData();
const intervalId = setInterval(fetchData, 60000 * 5);
return () => clearInterval(intervalId);
- }, [props.UserId,token]);
+ }, [props.UserId, token]);
return (
-
-
-
} />
-
} />
-
} />
-
} />
+
+
+
+
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
);