Skip to content

Commit 48271cc

Browse files
committed
working prototype
1 parent 8def4c6 commit 48271cc

7 files changed

Lines changed: 90 additions & 41 deletions

File tree

carousel.html

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
<div id="question">
1818
<img src="" alt="">
1919
<div id="buttons">
20-
<x-button>
20+
<x-button id="yes">
2121
<x-box vertical>
22-
<x-label id="yes">Accept</x-label>
22+
<x-label>Accept</x-label>
2323
<x-icon name='thumb-up'></x-icon>
2424
</x-box>
2525
</x-button>
26-
<x-button>
26+
<x-button id="no">
2727
<x-box vertical>
28-
<x-label id="no">Decline</x-label>
28+
<x-label>Decline</x-label>
2929
<x-icon name='thumb-down'></x-icon>
3030
</x-box>
3131
</x-button>
@@ -34,8 +34,11 @@
3434
</body>
3535
<script>
3636
window.onload = startCarousel();
37-
const btn = document.getElementById('yes');
38-
btn.addEventListener('click', nextQuestion);
37+
const yes = document.getElementById('yes');
38+
yes.addEventListener('click', nextQuestion);
39+
40+
const no = document.getElementById('no');
41+
no.addEventListener('click', nextQuestion);
3942
</script>
4043

4144
</html>

data.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"ID":"123","answers":[]}
1+
{"ID":"23","answers":[]}

src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ let mainWindow: Electron.BrowserWindow;
88
function createWindow() {
99
// Create the browser window.
1010
mainWindow = new BrowserWindow({
11-
height: 600,
12-
width: 800
11+
height: 300,
12+
width: 400
1313
});
1414

1515
// and load the index.html of the app.
@@ -22,7 +22,7 @@ function createWindow() {
2222
);
2323

2424
// Open the DevTools.
25-
mainWindow.webContents.openDevTools();
25+
// mainWindow.webContents.openDevTools();
2626

2727
// Emitted when the window is closed.
2828
mainWindow.on('closed', () => {

src/questions.ts

Lines changed: 73 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,74 @@
11
const fs = require('fs');
22
const path = require('path');
33
const BrowserWindow = electron.remote.BrowserWindow;
4+
45
class Question {
56
private correctAnswer: boolean;
67
private answer: boolean;
78
private questionImage: string;
89
private type: string;
910

10-
constructor(questionImage: string, type: string, correctAnswer: boolean) {
11+
constructor(
12+
questionImage: string,
13+
type: string,
14+
correctAnswer: boolean = true
15+
) {
1116
this.questionImage = questionImage;
1217
this.correctAnswer = correctAnswer;
1318
this.type = type;
1419
}
15-
public getQuestionImage() {
20+
public getImage() {
1621
return this.questionImage;
1722
}
23+
24+
public getType() {
25+
return this.type;
26+
}
1827
}
1928

20-
let timeHandle: number;
21-
let restartTimeout: number;
29+
const timeouts: { [key: string]: () => number } = {
30+
review: () => 10000,
31+
prose: () => 5000,
32+
fixation: () => 1000 * Math.floor(Math.random() * 6) + 2
33+
};
34+
35+
let timeHandle: any;
2236
let questions: Question[] = this.createQuestions();
2337
function startCarousel(): void {
38+
clearTimeout(timeHandle);
2439
function nextPicture(qs: Question[]) {
2540
const picture = qs.shift();
2641
if (picture) {
2742
replaceImage(picture);
28-
this.timeHandle = setTimeout(() => nextPicture(qs), 5000);
29-
} else {
30-
const el = document.querySelector('img');
31-
el.setAttribute('src', './assets/questions/fixation.jpg');
32-
const btnDiv = document.getElementById('buttons');
33-
btnDiv.style.visibility = 'hidden';
34-
this.restartTimeout = setTimeout(
35-
restart,
36-
1000 * Math.floor(Math.random() * 6) + 2
37-
);
43+
const type = picture.getType();
44+
timeHandle = setTimeout(() => nextPicture(qs), timeouts[type]());
45+
console.log('replace image');
46+
console.log(timeHandle);
3847
}
3948
}
4049
nextPicture(questions);
4150
}
42-
function restart() {
43-
console.log('restarting');
44-
clearTimeout(this.restartTimeout);
45-
const btnDiv = document.getElementById('buttons');
46-
btnDiv.style.visibility = 'visible';
47-
this.questions = this.createQuestions();
48-
startCarousel();
49-
}
51+
5052
function nextQuestion() {
5153
console.log('nextQuestion');
52-
clearTimeout(this.timeHandle);
54+
clearTimeout(timeHandle);
55+
console.log(timeHandle);
5356
startCarousel();
5457
}
5558

5659
function replaceImage(obj: Question) {
60+
const div = document.getElementById('buttons');
5761
const el = document.querySelector('img');
58-
el.setAttribute('src', `./assets/questions/review/${obj.getQuestionImage()}`);
62+
if (obj.getType() === 'fixation') {
63+
div.style.visibility = 'hidden';
64+
} else {
65+
div.style.visibility = 'visible';
66+
}
67+
68+
el.setAttribute(
69+
'src',
70+
`./assets/questions/${obj.getType()}/${obj.getImage()}`
71+
);
5972
}
6073

6174
function createQuestions(): Question[] {
@@ -64,23 +77,54 @@ function createQuestions(): Question[] {
6477
const questionArray: Question[] = [];
6578
fs
6679
.readdirSync(questionFolder)
67-
.sort(() => 0.5 - Math.random())
68-
.slice(0, 10)
80+
// .sort(() => 0.5 - Math.random())
81+
// .slice(0, 10)
6982
.forEach((file: any) => {
70-
const q = new Question(file, type, true);
83+
const q = new Question(file, type);
7184
questionArray.push(q);
7285
});
7386
return questionArray;
7487
}
7588
const qReview = createQuestionOfType('review');
7689
const qProse = createQuestionOfType('prose');
77-
return qReview;
90+
const block1: Question[] = qReview
91+
.splice(0, 3)
92+
.concat(qProse.splice(0, 6))
93+
.sort(() => 0.5 - Math.random());
94+
95+
const block2: Question[] = qReview
96+
.splice(0, 3)
97+
.concat(qProse.splice(0, 6))
98+
.sort(() => 0.5 - Math.random());
99+
100+
const block3: Question[] = qReview
101+
.splice(0, 3)
102+
.concat(qProse.splice(0, 6))
103+
.sort(() => 0.5 - Math.random());
104+
105+
const block4: Question[] = qReview
106+
.splice(0, 3)
107+
.concat(qProse.splice(0, 6))
108+
.sort(() => 0.5 - Math.random());
109+
110+
const fixation = new Question('fixation.jpg', 'fixation');
111+
const out: Question[] = block1.concat(
112+
fixation,
113+
block2,
114+
fixation,
115+
block3,
116+
fixation,
117+
block4
118+
);
119+
console.log(out);
120+
121+
return out;
78122
}
79123

80124
function createQuestionWindow(e: any): void {
81125
e.preventDefault();
82126
const carousel = path.join('file://', __dirname, 'carousel.html');
83-
let win = new BrowserWindow({ width: 500, height: 500 });
127+
let win = new BrowserWindow({ width: 800, height: 800 });
84128
win.on('close', () => (win = null));
85129
win.loadURL(carousel);
86130
}

src/subject.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ function createSubject(e: any): void {
1515
e.preventDefault();
1616
const id = document.querySelector('#subjectID') as HTMLInputElement;
1717
const s = new Subject(id.value);
18-
console.log(s);
1918
ipcRenderer.send('subject:create', s);
2019
}

styles/custom.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
body {
1010
height: 100vh;
1111
}
12-
12+
#questions {
13+
display: flex;
14+
}
1315
#buttons {
16+
align-self: flex-end;
1417
display: flex;
1518
flex-direction: row;
1619
justify-content: space-around;

0 commit comments

Comments
 (0)