Skip to content

Commit

Permalink
everything works as intended
Browse files Browse the repository at this point in the history
  • Loading branch information
Epic Martijn committed Nov 4, 2020
1 parent 696f5fe commit c14a457
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 5 deletions.
5 changes: 2 additions & 3 deletions DataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ class DataStore extends Store {
}

getRandomEntry () {
// set object's entries to entries in JSON file

return this.entries[Math.floor(Math.random() * this.entries.length)];
// gets random entry
return (this.get('entries') || [])[Math.floor(Math.random() * this.entries.length)];
}

addEntry (entry) {
Expand Down
6 changes: 5 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ function createWindow () {
win.loadFile(path.join('renderer', 'index.html'));

ipcMain.on('get-entries', (event) => {
win.send('entries', store.entries);
win.send('entries', store.getEntries().entries);
});

ipcMain.on('random-entry', (event) => {
win.send('entry', store.getRandomEntry());
});

ipcMain.on('add-entry', (event, entry) => {
Expand Down
Binary file added renderer/assets/img/avataaars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion renderer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<header class="masthead bg-primary text-white text-center">
<div class="container d-flex align-items-center flex-column">
<!-- Masthead Avatar Image-->
<img class="masthead-avatar mb-5" src="assets/img/avataaars.svg" alt="" />
<img class="masthead-avatar mb-5" src="assets/img/avataaars.png" alt="" />
<!-- Masthead Heading-->
<h1 class="masthead-heading text-uppercase mb-0">German Training</h1>
<!-- Icon Divider-->
Expand Down
96 changes: 96 additions & 0 deletions renderer/train.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="" />
<meta name="author" content="" />
<title>Time to practice</title>
<!-- Favicon-->
<link rel="icon" type="image/x-icon" href="assets/img/favicon.ico" />
<!-- Font Awesome icons (free version)-->
<script src="https://use.fontawesome.com/releases/v5.13.0/js/all.js" crossorigin="anonymous"></script>
<!-- Google fonts-->
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css" />
<link href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic" rel="stylesheet"
type="text/css" />
<!-- Core theme CSS (includes Bootstrap)-->
<link href="css/styles.css" rel="stylesheet" />
</head>

<body id="page-top">
<!-- Navigation-->
<nav class="navbar navbar-expand-lg bg-secondary text-uppercase static-top" id="mainNav">
<div class="container">
<a class="navbar-brand js-scroll-trigger" href="index.html">German Training</a>
<button
class="navbar-toggler navbar-toggler-right text-uppercase font-weight-bold bg-primary text-white rounded"
type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive"
aria-expanded="false" aria-label="Toggle navigation">
Menu
<i class="fas fa-bars"></i>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item mx-0 mx-lg-1"><a class="nav-link py-3 px-0 px-lg-3 rounded js-scroll-trigger"
href="train.html">Train</a></li>
<li class="nav-item mx-0 mx-lg-1"><a class="nav-link py-3 px-0 px-lg-3 rounded js-scroll-trigger"
href="edit.html">Edit Word list</a></li>

</ul>
</div>
</div>
</nav>
<!-- Masthead-->
<div class="container question-container">
<div class="d-flex justify-content-center">
<form id="question-form" class="p-5 m-5" onsubmit="return false">
<div id="wrong-answer" class="alert alert-danger" style="display: none;" role="alert">
Oh no! that is not correct.
</div>
<div class="form-group">
<label for="answer" id="question"></label>
<input type="answer" class="form-control" id="answer" placeholder="Enter answer">
</div>
<button id="submit-button" type="submit" class="btn btn-primary">Submit</button>
<button id="show-answer" onclick="return false;" class="btn btn-primary">Show answer</button>
</form>

</div>

</div>
<div class="container good-container" style="display: none;">
<div class="d-flex justify-content-center p-5 m-5">
<div class="row flex-column">
<h1>Good job</h1>
<button id="next-question" class="btn btn-primary">Next question</button>
</div>

</div>

</div>



<!-- Scroll to Top Button (Only visible on small and extra-small screen sizes)-->
<div class="scroll-to-top d-lg-none position-fixed">
<a class="js-scroll-trigger d-block text-center text-white rounded" href="#page-top"><i
class="fa fa-chevron-up"></i></a>
</div>


<!-- Core theme JS-->
<script>
window.$ = window.jQuery = require('jquery');
</script>
<script>
window.$ = window.jQuery = require('jquery-ui');
</script>
<script src="js/scripts.js"></script>
<script src="train.js"></script>


</body>

</html>
44 changes: 44 additions & 0 deletions renderer/train.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';
const { ipcRenderer } = require('electron');
$ = require('jquery');

var question;
var answer;

ipcRenderer.on('entry', (event, entry) => {
question = entry.question;
answer = entry.answer;
console.log(entry);
$('#question').text(question);
});

$("#question-form").on('submit', () => {
if($('#question-form :input').val() == answer){
$('.question-container').hide();
$(".good-container").show();
}
else {
$("#wrong-answer").show();
}
});
$("#next-question").on('click', () => {
$('.question-container').show();
$("#wrong-answer").hide();
$(".good-container").hide();
$("#answer").val("");
ipcRenderer.send('random-entry');
});

$("#show-answer").on('click', () => {
$("#wrong-answer").hide();
$("#answer").val(answer);

});

$(function() {
ipcRenderer.send('random-entry');
});




0 comments on commit c14a457

Please sign in to comment.