-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
83 lines (71 loc) · 2.63 KB
/
index.html
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>LeetCode Study App</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>AlgoAscent</h1>
<p id="recommendation"></p>
<div id="reportForm">
<label for="timeTaken">Time Taken (minutes):</label>
<input type="number" id="timeTaken" name="timeTaken" step="0.1" required><br>
<label for="solved">Solved:</label>
<input type="checkbox" id="solved" name="solved"><br>
<button id="submitReportBtn">Submit Report</button>
</div>
<script>
let currentProblem = null;
function fetchRecommendation() {
fetch('http://localhost:8000/recommend')
.then(response => response.json())
.then(data => {
currentProblem = data;
const recommendationElement = document.getElementById('recommendation');
recommendationElement.innerHTML = `Try: <a href="${data.url}" id="leetcodeLink">${data.title}</a>`;
// Add the event listener to open the link using the electron api.
document.getElementById('leetcodeLink').addEventListener('click', (event) => {
event.preventDefault();
const { shell } = require('electron');
shell.openExternal(data.url);
})
})
.catch(err => console.error(err));
}
function clearReportForm() {
document.getElementById('timeTaken').value = '';
document.getElementById('solved').checked = false;
}
// Fetch a recommendation on load
fetchRecommendation()
// Send a sample report when the button is clicked
document.getElementById('submitReportBtn').addEventListener('click', () => {
const timeTaken = document.getElementById('timeTaken').value;
const solved = document.getElementById('solved').checked;
if (!currentProblem) {
alert("Cannot submit report. No problem has been loaded yet.");
return;
}
fetch('http://localhost:8000/report', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
problem_id: currentProblem.id,
time_taken: parseFloat(timeTaken),
solved: solved
})
})
.then(response => response.json())
.then(data => {
console.log(data)
clearReportForm()
fetchRecommendation()
})
.catch(err => console.error(err));
});
</script>
</body>
</html>