Skip to content

Commit

Permalink
1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Xxsource98 committed Jan 17, 2022
1 parent a6e6bde commit fd34315
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 38 deletions.
8 changes: 7 additions & 1 deletion electron/handleMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
15 changes: 14 additions & 1 deletion electron/librusData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(() => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "v-librus",
"version": "1.0.6",
"version": "1.0.7",
"private": true,
"author": "Xxsource98 <fake@xx.com>",
"license": "GPL-3.0",
Expand Down
2 changes: 1 addition & 1 deletion src/.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.6
1.0.7
27 changes: 15 additions & 12 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -26,25 +26,28 @@ const App = () => {
}
});
const [ currentPanel, setCurrentPanel ] = useState('Home');
const [ messagesContext, setMessagesContext ] = useState([]);

return (
<Router>
<AnimatePresence exitBeforeEnter>
<Switch>
<GlobalDataContext.Provider value={[dataContext, setDataContext]}>
<ShortcutsPanelContext.Provider value={[currentPanel, setCurrentPanel]}>
<HandleRefresh />
<Titlebar />
<Route exact path="/" component={LoginForm} />
<Route exact path="/panel" component={Panel} />
<MessagesContext.Provider value={[messagesContext, setMessagesContext]}>
<HandleRefresh />
<Titlebar />
<Route exact path="/" component={LoginForm} />
<Route exact path="/panel" component={Panel} />

<Route exact path="/panel/allCalendarWidgets/:type" component={AllCalendarWidgets} />
<Route exact path="/panel/schedule" component={Schedule} />
<Route exact path="/panel/grades" component={Grades} />
<Route exact path="/panel/messages" component={Messages} />
<Route exact path="/panel/notifications" component={Notifications} />
<Route exact path="/panel/absences" component={Absences} />
<PanelShortcuts />
<Route exact path="/panel/allCalendarWidgets/:type" component={AllCalendarWidgets} />
<Route exact path="/panel/schedule" component={Schedule} />
<Route exact path="/panel/grades" component={Grades} />
<Route exact path="/panel/messages" component={Messages} />
<Route exact path="/panel/notifications" component={Notifications} />
<Route exact path="/panel/absences" component={Absences} />
<PanelShortcuts />
</MessagesContext.Provider>
</ShortcutsPanelContext.Provider>
</GlobalDataContext.Provider>
</Switch>
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Panel/Absences/absences.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.absences {
display: flex;
width: 95vw;
width: 100%;
margin-left: auto;
margin-right: auto;
height: auto;
Expand Down
15 changes: 13 additions & 2 deletions src/Components/Panel/AllCalendarWidgets/getAllWidgets.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className='no-events'>
<p>There aren't any {EventName} soon</p>
</div>
);
}
else {
return returnData;
}
}

export default CreateWidgets;
13 changes: 13 additions & 0 deletions src/Components/Panel/AllCalendarWidgets/widgets.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/Components/Panel/Grades/grades.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const Grades = () => {
return isNaN(result) ? "-" : result;
}

const drawGradesRows = () => {
const DrawGradesRows = () => {
let grades = dataContext.librusData.grades;
let returnData = [];

Expand All @@ -196,13 +196,13 @@ const Grades = () => {
<tr key={`${grade.subject}`}>
<td>{grade.subject}</td>
<td>{drawGradesWidgets(gradesList.normal, grade.subject)}</td>
<td style={{textAlign: 'center', color: average < 1.75 ? '#e74c3c' : ''}}>{calculateAverageGrade(gradesList.normal)}</td>
<td style={{textAlign: 'center', fontWeight: '500'}}>{gradesList.final === "" ? "-" : gradesList.final}</td>
<td style={{textAlign: 'center', color: average < 2 ? '#e74c3c' : ''}}>{calculateAverageGrade(gradesList.normal)}</td>
<td style={{textAlign: 'center', fontWeight: '500'}}>{gradesList.final.grade === "" ? "-" : gradesList.final.grade}</td>
</tr>
)
}

return returnData;
return (<>{returnData}</>);
}

const DrawGradesTable = () => {
Expand Down Expand Up @@ -258,7 +258,7 @@ const Grades = () => {
</tr>
</thead>
<tbody>
{drawGradesRows()}
<DrawGradesRows />
</tbody>
</table>
)
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Panel/Grades/grades.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.grades {
display: flex;
width: 95vw;
width: 100%;
margin-left: auto;
margin-right: auto;
height: auto;
Expand Down
37 changes: 27 additions & 10 deletions src/Components/Panel/Messages/messages.jsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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");
Expand Down Expand Up @@ -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(
<tr data-value={message.id} className={message.read ? "readed" : "not-readed"} onClick={click => switchActiveTr(click)} key={message.id}>
<tr data-value={message.id} className={message.read ? "readed" : "not-readed"} onClick={click => switchActiveTr(click, message)} key={message.id}>
<td>{message.user}</td>
<td>{message.title}</td>
<td>{message.date}</td>
Expand Down Expand Up @@ -117,16 +129,21 @@ const Messages = () => {
<div className="panel-section panel-padding">
<p className="panel-header">Messages</p>
<NavigatePanel />
<div className="messages">
<DrawMessagesTable />
<div className={`messages ${promiseInProgress ? 'loading' : ''}`}>
{
promiseInProgress ?
<img src={LoadingIcon} alt={LoadingIcon} />
:
<DrawMessagesTable />
}
</div>
</div>
</div>
);

return (
<MainPanel componentInside={componentToDraw} />
)
);
}

export default Messages;
2 changes: 1 addition & 1 deletion src/Components/Panel/Schedule/schedule.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.schedule {
display: flex;
width: 95vw;
width: 100%;
margin-left: auto;
margin-right: auto;
height: auto;
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Panel/panel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $panelHeight: 50px;
left: 15px;
width: 65%;
font-size: 1.4rem;
font-weight: 300;
font-weight: 400;
}

.widgets {
Expand Down
1 change: 1 addition & 0 deletions src/Components/Panel/panelShortcuts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
width: 100%;
box-sizing: border-box;
backdrop-filter: blur(25px);
z-index: 99;

.shortcut {
box-sizing: border-box;
Expand Down
1 change: 1 addition & 0 deletions src/Components/handleRefresh.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/globalContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import React from 'react';

const GlobalDataContext = React.createContext();
const ShortcutsPanelContext = React.createContext();
const MessagesContext = React.createContext();

export { GlobalDataContext, ShortcutsPanelContext }
export { GlobalDataContext, ShortcutsPanelContext, MessagesContext }

0 comments on commit fd34315

Please sign in to comment.