forked from bilalaniq/CTF-Scheduler---Electron-App
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex_scripts.js
More file actions
54 lines (43 loc) · 1.71 KB
/
index_scripts.js
File metadata and controls
54 lines (43 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const { ipcRenderer } = require('electron');
const path = require('path');
// Add team button listener to redirect to add_team.html
const addTeamButton = document.getElementById('add_team_btn');
addTeamButton.addEventListener('click', () => {
window.location.href = "add_team.html";
});
// Function to fetch CTF data from the main process
async function getCTF() {
try {
const { ctfData, teamsLength } = await ipcRenderer.invoke('get-ctf'); // Get CTF data and teams length
return { ctfData, teamsLength }; // Return both the CTF data and the length of the teams
} catch (error) {
console.error('Failed to fetch CTF:', error);
alert('Error fetching CTF data');
}
}
const team_detail_btn = document.getElementById('full_team_detail');
team_detail_btn.addEventListener('click', async () => {
const { ctfData, teamsLength } = await getCTF();
// Check if the CTF data is incomplete
if (!ctfData || !ctfData.teams_name || ctfData.teams_name.length === 0) {
alert('Please add teams to see the team details');
return;
}
// If teams exist, redirect to full_team_detail.html
window.location.href = "full_team_detail.html";
});
// Round button listener to redirect to rounds.html
const round_btn = document.getElementById('round_btn');
round_btn.addEventListener('click', async () => {
// const { ctfData, teamsLength } = await getCTF();
// // Check if the CTF data is incomplete
// if (!ctfData || !ctfData.teams || ctfData.teams.length === 0) {
// alert('Please add teams to go to rounds');
// return;
// }
window.location.href = "rounds.html";
});
const about = document.getElementById('about_btn');
about.addEventListener('click', async () => {
window.location.href = "about.html";
});