From fd34315aeadf07d7c4366f788214770885832b01 Mon Sep 17 00:00:00 2001 From: Xxsource98 Date: Tue, 18 Jan 2022 00:21:02 +0100 Subject: [PATCH] 1.0.7 --- electron/handleMessages.js | 8 +++- electron/librusData.js | 15 +++++++- package.json | 2 +- src/.version | 2 +- src/App.js | 27 ++++++++------ src/Components/Panel/Absences/absences.scss | 2 +- .../AllCalendarWidgets/getAllWidgets.jsx | 15 +++++++- .../Panel/AllCalendarWidgets/widgets.scss | 13 +++++++ src/Components/Panel/Grades/grades.jsx | 10 ++--- src/Components/Panel/Grades/grades.scss | 2 +- src/Components/Panel/Messages/messages.jsx | 37 ++++++++++++++----- src/Components/Panel/Schedule/schedule.scss | 2 +- src/Components/Panel/panel.scss | 2 +- src/Components/Panel/panelShortcuts.scss | 1 + src/Components/handleRefresh.jsx | 1 + src/globalContext.jsx | 3 +- 16 files changed, 104 insertions(+), 38 deletions(-) diff --git a/electron/handleMessages.js b/electron/handleMessages.js index 03187cf..eb232ee 100644 --- a/electron/handleMessages.js +++ b/electron/handleMessages.js @@ -161,7 +161,13 @@ const HandleMessages = ( const data = await librusData.getAbsenceInfo(absenceID); return data; - }) + }); + + ipcMain.handle('fetch-messages', async ev => { + const data = await librusData.fetchMessages(5); + + return data; + }); } module.exports = HandleMessages; \ No newline at end of file diff --git a/electron/librusData.js b/electron/librusData.js index cf1241d..4e8a344 100644 --- a/electron/librusData.js +++ b/electron/librusData.js @@ -361,7 +361,7 @@ class librusData { await this.librusData.inbox.listAnnouncements().then(data => dataToSend.notifications = data); - await this.librusData.inbox.listInbox(5).then(async data => dataToSend.messages = data); + //await this.librusData.inbox.listInbox(5).then(async data => dataToSend.messages = data); await this.librusData.info.getLuckyNumber().then(data => { const luckyNumber = parseInt(data); @@ -388,6 +388,19 @@ class librusData { }); } + fetchMessages(inboxID) { // Default inboxID is 5 + return new Promise(async (resolve, reject) => { + await this.librusData.inbox.listInbox(inboxID).then(async data => { + if (data !== null) { + resolve(data); + } + else { + reject('Failed'); + } + }); + }); + } + login(login, password) { return new Promise((resolve, reject) => { this.librusData.authorize(login, password).then(() => { diff --git a/package.json b/package.json index a005b2c..2be025a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "v-librus", - "version": "1.0.6", + "version": "1.0.7", "private": true, "author": "Xxsource98 ", "license": "GPL-3.0", diff --git a/src/.version b/src/.version index ece61c6..f9cbc01 100644 --- a/src/.version +++ b/src/.version @@ -1 +1 @@ -1.0.6 \ No newline at end of file +1.0.7 \ No newline at end of file diff --git a/src/App.js b/src/App.js index 0b609e9..c155e4e 100644 --- a/src/App.js +++ b/src/App.js @@ -2,7 +2,7 @@ import React, { useState } from 'react'; import { HashRouter as Router, Switch, Route } from 'react-router-dom'; import { AnimatePresence } from 'framer-motion'; -import { GlobalDataContext, ShortcutsPanelContext } from './globalContext'; +import { GlobalDataContext, ShortcutsPanelContext, MessagesContext } from './globalContext'; import PanelShortcuts from './Components/Panel/panelShortcuts'; import HandleRefresh from './Components/handleRefresh'; @@ -26,6 +26,7 @@ const App = () => { } }); const [ currentPanel, setCurrentPanel ] = useState('Home'); + const [ messagesContext, setMessagesContext ] = useState([]); return ( @@ -33,18 +34,20 @@ const App = () => { - - - - + + + + + - - - - - - - + + + + + + + + diff --git a/src/Components/Panel/Absences/absences.scss b/src/Components/Panel/Absences/absences.scss index 26ebefd..d5e3963 100644 --- a/src/Components/Panel/Absences/absences.scss +++ b/src/Components/Panel/Absences/absences.scss @@ -1,6 +1,6 @@ .absences { display: flex; - width: 95vw; + width: 100%; margin-left: auto; margin-right: auto; height: auto; diff --git a/src/Components/Panel/AllCalendarWidgets/getAllWidgets.jsx b/src/Components/Panel/AllCalendarWidgets/getAllWidgets.jsx index 81dd207..177055e 100644 --- a/src/Components/Panel/AllCalendarWidgets/getAllWidgets.jsx +++ b/src/Components/Panel/AllCalendarWidgets/getAllWidgets.jsx @@ -102,8 +102,19 @@ const CreateWidgets = ({ returnData.push(element.widget); } - - return (<>{returnData}); + + if (returnData.length === 0) { + const EventName = type === 'appeal' ? 'Appeals and Shifts' : type === 'test' ? 'Tests' : 'Absences'; + + return ( +
+

There aren't any {EventName} soon

+
+ ); + } + else { + return returnData; + } } export default CreateWidgets; \ No newline at end of file diff --git a/src/Components/Panel/AllCalendarWidgets/widgets.scss b/src/Components/Panel/AllCalendarWidgets/widgets.scss index 3906d2d..077a2a3 100644 --- a/src/Components/Panel/AllCalendarWidgets/widgets.scss +++ b/src/Components/Panel/AllCalendarWidgets/widgets.scss @@ -8,6 +8,19 @@ padding-bottom: 15px; transform-origin: left right; + .no-events { + width: 100%; + display: flex; + justify-content: center; + align-items: center; + height: 100px; + font-weight: 300; + + p { + color: #f3f3f3; + } + } + .widget { position: relative; background-color: rgb(49, 49, 49); diff --git a/src/Components/Panel/Grades/grades.jsx b/src/Components/Panel/Grades/grades.jsx index 935fb3b..fac535b 100644 --- a/src/Components/Panel/Grades/grades.jsx +++ b/src/Components/Panel/Grades/grades.jsx @@ -184,7 +184,7 @@ const Grades = () => { return isNaN(result) ? "-" : result; } - const drawGradesRows = () => { + const DrawGradesRows = () => { let grades = dataContext.librusData.grades; let returnData = []; @@ -196,13 +196,13 @@ const Grades = () => { {grade.subject} {drawGradesWidgets(gradesList.normal, grade.subject)} - {calculateAverageGrade(gradesList.normal)} - {gradesList.final === "" ? "-" : gradesList.final} + {calculateAverageGrade(gradesList.normal)} + {gradesList.final.grade === "" ? "-" : gradesList.final.grade} ) } - return returnData; + return (<>{returnData}); } const DrawGradesTable = () => { @@ -258,7 +258,7 @@ const Grades = () => { - {drawGradesRows()} + ) diff --git a/src/Components/Panel/Grades/grades.scss b/src/Components/Panel/Grades/grades.scss index 9d4d50c..847b3e6 100644 --- a/src/Components/Panel/Grades/grades.scss +++ b/src/Components/Panel/Grades/grades.scss @@ -1,6 +1,6 @@ .grades { display: flex; - width: 95vw; + width: 100%; margin-left: auto; margin-right: auto; height: auto; diff --git a/src/Components/Panel/Messages/messages.jsx b/src/Components/Panel/Messages/messages.jsx index 2bb6deb..221c4c0 100644 --- a/src/Components/Panel/Messages/messages.jsx +++ b/src/Components/Panel/Messages/messages.jsx @@ -1,6 +1,7 @@ import React, { useContext, useEffect, useCallback } from 'react'; +import { trackPromise, usePromiseTracker } from 'react-promise-tracker'; -import { GlobalDataContext, ShortcutsPanelContext } from '../../../globalContext'; +import { MessagesContext, ShortcutsPanelContext } from '../../../globalContext'; import { MainPanel, NavigatePanel } from '../mainPanel'; import Arrow from '../../../Images/img/Arrow.png'; @@ -12,26 +13,35 @@ import './messages.scss'; const ipcRenderer = window.require("electron").ipcRenderer; const Messages = () => { - const [ dataContext, ] = useContext(GlobalDataContext); + const { promiseInProgress } = usePromiseTracker(); + const [ messagesContext, setMessagesContext ] = useContext(MessagesContext); const [ currentPanel, setCurrentPanel ] = useContext(ShortcutsPanelContext); console.log('Yes I know there is a big mistake with div append in the table cell but idc, it works so I can be happy lol'); - + const CheckPanel = useCallback((panel) => { if (currentPanel !== panel) { setCurrentPanel(panel); } - }, [currentPanel, setCurrentPanel]); + + if (messagesContext.length === 0) { + trackPromise(ipcRenderer.invoke('fetch-messages').then(data => { + if (data !== 'Failed') { + setMessagesContext(data); + } + })); + } + }, [currentPanel, setCurrentPanel, messagesContext, setMessagesContext]); useEffect(() => { CheckPanel('Messages'); }, [CheckPanel]); const DrawMessages = () => { - const allMessages = dataContext.librusData.messages; + const allMessages = messagesContext; let returnData = []; - const switchActiveTr = async click => { + const switchActiveTr = async (click, message) => { const target = click.target.parentElement; const messageDiv = target.nextElementSibling; const tbody = document.querySelector("tbody"); @@ -67,12 +77,14 @@ const Messages = () => { if (target.classList.contains("not-readed")) { target.classList.remove("not-readed"); target.classList.add("readed"); + + message.read = true; } } for (const message of allMessages) { returnData.push( - switchActiveTr(click)} key={message.id}> + switchActiveTr(click, message)} key={message.id}> {message.user} {message.title} {message.date} @@ -117,8 +129,13 @@ const Messages = () => {

Messages

-
- +
+ { + promiseInProgress ? + {LoadingIcon} + : + + }
@@ -126,7 +143,7 @@ const Messages = () => { return ( - ) + ); } export default Messages; \ No newline at end of file diff --git a/src/Components/Panel/Schedule/schedule.scss b/src/Components/Panel/Schedule/schedule.scss index ea48d4f..cbddbcd 100644 --- a/src/Components/Panel/Schedule/schedule.scss +++ b/src/Components/Panel/Schedule/schedule.scss @@ -1,6 +1,6 @@ .schedule { display: flex; - width: 95vw; + width: 100%; margin-left: auto; margin-right: auto; height: auto; diff --git a/src/Components/Panel/panel.scss b/src/Components/Panel/panel.scss index 2a018ed..00434eb 100644 --- a/src/Components/Panel/panel.scss +++ b/src/Components/Panel/panel.scss @@ -27,7 +27,7 @@ $panelHeight: 50px; left: 15px; width: 65%; font-size: 1.4rem; - font-weight: 300; + font-weight: 400; } .widgets { diff --git a/src/Components/Panel/panelShortcuts.scss b/src/Components/Panel/panelShortcuts.scss index 380becc..7e6a43e 100644 --- a/src/Components/Panel/panelShortcuts.scss +++ b/src/Components/Panel/panelShortcuts.scss @@ -7,6 +7,7 @@ width: 100%; box-sizing: border-box; backdrop-filter: blur(25px); + z-index: 99; .shortcut { box-sizing: border-box; diff --git a/src/Components/handleRefresh.jsx b/src/Components/handleRefresh.jsx index 21a3679..c7176b5 100644 --- a/src/Components/handleRefresh.jsx +++ b/src/Components/handleRefresh.jsx @@ -10,6 +10,7 @@ const HandleRefresh = () => { const RefreshCallback = useCallback(() => { if (dataContext.loginData.isLogged) { const timer = setTimeout(() => { + dataContext.loginData.isLogged = false; history.go('/'); }, 1800000); // Refresh in 30 minutes for "refresh" data return () => clearTimeout(timer); diff --git a/src/globalContext.jsx b/src/globalContext.jsx index a41b305..3b58c17 100644 --- a/src/globalContext.jsx +++ b/src/globalContext.jsx @@ -2,5 +2,6 @@ import React from 'react'; const GlobalDataContext = React.createContext(); const ShortcutsPanelContext = React.createContext(); +const MessagesContext = React.createContext(); -export { GlobalDataContext, ShortcutsPanelContext } \ No newline at end of file +export { GlobalDataContext, ShortcutsPanelContext, MessagesContext } \ No newline at end of file