Pārlūkot izejas kodu

get questionnaire

master
DemiSel 2 gadus atpakaļ
vecāks
revīzija
8023804de2

+ 6
- 0
backend/.idea/encodings.xml Parādīt failu

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="Encoding">
4
+    <file url="PROJECT" charset="UTF-8" />
5
+  </component>
6
+</project>

+ 4
- 0
backend/build.gradle Parādīt failu

@@ -10,6 +10,10 @@ repositories {
10 10
 }
11 11
 
12 12
 dependencies {
13
+    compile 'com.github.cliftonlabs:json-simple:3.1.1'
14
+}
15
+
16
+dependencies {
13 17
     testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
14 18
     testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
15 19
 }

+ 64
- 0
backend/src/main/java/Application.java Parādīt failu

@@ -1,2 +1,66 @@
1
+import api.ResponseHandler;
2
+import com.sun.net.httpserver.HttpServer;
3
+import model.personnality.Trait;
4
+import model.questionnaire.Answer;
5
+import model.questionnaire.Question;
6
+import model.questionnaire.Questionnaire;
7
+
8
+import java.net.InetSocketAddress;
9
+import java.util.Arrays;
10
+
1 11
 public class Application {
12
+
13
+    public static void main(String [] args)
14
+    {
15
+        Trait vExtrovertTrait = new Trait("Extrovert", "You're an extrovert");
16
+        Trait vIntrovertTrait = new Trait("Introvert", "You're an introvert");
17
+
18
+        //------------------------------------
19
+        // Define questionnaire
20
+        //------------------------------------
21
+        Questionnaire vQuestionnaire = new Questionnaire(
22
+                "Introvert or extrovert ?",
23
+                Arrays.asList(
24
+                        //------------------------------------
25
+                        // First question
26
+                        //------------------------------------
27
+                        new Question(
28
+                                "You're really busy at work and a colleague is telling you their life story and personal woes.",
29
+                                Arrays.asList(
30
+                                        new Answer("Don't dare to interrupt them", vIntrovertTrait, 0.5f),
31
+                                        new Answer("Think it's more important to give them some of your time; work can wait", vIntrovertTrait, 0.2f),
32
+                                        new Answer("Listen, but with only with half an ear ", vIntrovertTrait, 0.1f),
33
+                                        new Answer("Interrupt and explain that you are really busy at the moment", vExtrovertTrait, 0.5f)
34
+                                )
35
+                        ),
36
+                        //------------------------------------
37
+                        // Second question
38
+                        //------------------------------------
39
+                        new Question(
40
+                                "You've been sitting in the doctor's waiting room for more than 25 minutes.",
41
+                                Arrays.asList(
42
+                                        new Answer("Look at your watch every two minutes", vIntrovertTrait, 0.2f),
43
+                                        new Answer("Bubble with inner anger, but keep quiet ", vIntrovertTrait, 0.5f),
44
+                                        new Answer("Explain to other equally impatient people in the room that the doctor is always running late ", vExtrovertTrait, 0.3f),
45
+                                        new Answer("Complain in a loud voice, while tapping your foot impatiently", vExtrovertTrait, 0.7f)
46
+                                )
47
+                        )
48
+                )
49
+        );
50
+
51
+        //------------------------------------
52
+        // Start server
53
+        //------------------------------------
54
+        try {
55
+            HttpServer vServer = HttpServer.create(new InetSocketAddress(8080), 0);
56
+            vServer.createContext("/", new ResponseHandler());
57
+            vServer.setExecutor(null);
58
+            vServer.start();
59
+        }
60
+        catch(Exception ve)
61
+        {
62
+            ve.printStackTrace();
63
+        }
64
+    }
65
+
2 66
 }

+ 105
- 0
backend/src/main/java/api/ResponseHandler.java Parādīt failu

@@ -0,0 +1,105 @@
1
+package api;
2
+
3
+import com.github.cliftonlabs.json_simple.JsonObject;
4
+import com.github.cliftonlabs.json_simple.Jsoner;
5
+import com.sun.net.httpserver.HttpExchange;
6
+import com.sun.net.httpserver.HttpHandler;
7
+import controller.ModelController;
8
+import controller.QuestionnaireController;
9
+
10
+import java.io.IOException;
11
+import java.io.OutputStream;
12
+import java.nio.charset.StandardCharsets;
13
+import java.util.Arrays;
14
+
15
+public class ResponseHandler implements HttpHandler {
16
+
17
+    public JsonObject getResponse(String iMethod, String [] iPath, String iBody, ModelController iController)
18
+    {
19
+        JsonObject vResponseObject = new JsonObject();
20
+        JsonObject vRequestJson = new JsonObject();
21
+
22
+        try {
23
+            // ---------------------------------
24
+            // parse request body : either empty or a JSON Object
25
+            // ---------------------------------
26
+            if (iBody.length() > 0) {
27
+                Jsoner.deserialize(iBody, vRequestJson);
28
+            }
29
+
30
+            // ---------------------------------
31
+            // Decide which controller method should process the request
32
+            // ---------------------------------
33
+            switch (iMethod) {
34
+                case "GET":
35
+                    switch (iPath.length) {
36
+                        case 0:
37
+                            vResponseObject = iController.getAllEntries(vRequestJson); break;
38
+                        case 1:
39
+                            vResponseObject = iController.getEntriesForId(iPath[0], vRequestJson); break;
40
+                        default: throw new Exception(String.format("GET with %d subdirectories not implemented", iPath.length));
41
+                    }
42
+                    break;
43
+                case "POST":
44
+                    switch (iPath.length) {
45
+                        case 1: vResponseObject = iController.createEntry(vRequestJson); break;
46
+                        default: throw new Exception(String.format("POST with %d subdirectories not implemented", iPath.length));
47
+                    }
48
+                    break;
49
+                case "PUT":
50
+                    switch (iPath.length) {
51
+                        case 1: vResponseObject = iController.updateEntry(iPath[0], vRequestJson); break;
52
+                        default: throw new Exception(String.format("PUT with %d subdirectories not implemented", iPath.length));
53
+                    }
54
+                    break;
55
+                case "DELETE":
56
+                    switch (iPath.length) {
57
+                        case 1: vResponseObject = iController.deleteEntry(iPath[0]); break;
58
+                        default: throw new Exception(String.format("DELETE with %d subdirectories not implemented", iPath.length));
59
+                    }break;
60
+                default: throw new Exception(String.format("Method '%s' not implemented", iMethod));
61
+            }
62
+        }catch(Exception vex)
63
+        {
64
+            vResponseObject.put("error",vex.getMessage());
65
+        }
66
+
67
+        return vResponseObject;
68
+    }
69
+
70
+    @Override
71
+    public void handle(HttpExchange iExchange) throws IOException {
72
+        ModelController vController;
73
+        byte[] vRequestAnswerBytes;
74
+        OutputStream vOutputStream = iExchange.getResponseBody();
75
+        String[] vRequestURI = iExchange.getRequestURI().getPath().split("/");
76
+        String vRequestMethod = iExchange.getRequestMethod();
77
+        String vRequestBody = new String(iExchange.getRequestBody().readAllBytes());
78
+
79
+        try {
80
+            if(vRequestURI.length < 1)
81
+                throw new Exception(String.format("Unusable path '%s'", iExchange.getRequestURI().getPath()));
82
+
83
+            switch (vRequestURI[1]) {
84
+                case "questionnaire":
85
+                    vController = new QuestionnaireController();
86
+                    break;
87
+                default:
88
+                    throw new Exception(String.format("Unknown path '%s'", vRequestURI[1]));
89
+            }
90
+
91
+            vRequestAnswerBytes = getResponse(vRequestMethod, Arrays.copyOfRange(vRequestURI,2, vRequestURI.length), vRequestBody, vController).toJson().getBytes(StandardCharsets.UTF_8);
92
+            iExchange.getResponseHeaders().set("Content-Type","application/json; charset=utf-8");
93
+            iExchange.getResponseHeaders().set("Access-Control-Allow-Origin", "*");
94
+            iExchange.sendResponseHeaders(200, vRequestAnswerBytes.length);
95
+        }
96
+        catch(Exception vex){
97
+            vex.printStackTrace();
98
+            iExchange.sendResponseHeaders(405, vex.getMessage().getBytes(StandardCharsets.UTF_8).length);
99
+            vRequestAnswerBytes = vex.getMessage().getBytes(StandardCharsets.UTF_8);
100
+            }
101
+
102
+        vOutputStream.write(vRequestAnswerBytes);
103
+        vOutputStream.close();
104
+    }
105
+}

+ 27
- 0
backend/src/main/java/controller/ModelController.java Parādīt failu

@@ -0,0 +1,27 @@
1
+package controller;
2
+
3
+import com.github.cliftonlabs.json_simple.JsonObject;
4
+
5
+public abstract class ModelController {
6
+
7
+    public JsonObject getAllEntries(JsonObject iBody) throws Exception{
8
+        throw new Exception("Not implemented");
9
+    }
10
+
11
+    public JsonObject getEntriesForId(String iId, JsonObject iBody) throws Exception{
12
+        throw new Exception("Not implemented");
13
+    }
14
+
15
+    public JsonObject createEntry(JsonObject iBody) throws Exception{
16
+        throw new Exception("Not implemented");
17
+    }
18
+
19
+    public JsonObject updateEntry(String iID, JsonObject iBody) throws Exception{
20
+        throw new Exception("Not implemented");
21
+    }
22
+
23
+    public JsonObject deleteEntry(String iId) throws Exception{
24
+        throw new Exception("Not implemented");
25
+    }
26
+
27
+}

+ 12
- 0
backend/src/main/java/controller/QuestionnaireController.java Parādīt failu

@@ -0,0 +1,12 @@
1
+package controller;
2
+
3
+import com.github.cliftonlabs.json_simple.JsonObject;
4
+import model.questionnaire.Questionnaire;
5
+
6
+public class QuestionnaireController extends ModelController {
7
+
8
+    public JsonObject getAllEntries(JsonObject iJsonObject)
9
+    {
10
+        return Questionnaire.getTheOnlyExistingQuestionnaire().asJsonObject();
11
+    }
12
+}

+ 13
- 0
backend/src/main/java/model/personnality/Personality.java Parādīt failu

@@ -0,0 +1,13 @@
1
+package model.personnality;
2
+
3
+import java.util.HashMap;
4
+
5
+public class Personality {
6
+
7
+    private HashMap<Trait, Float> fTraits;
8
+
9
+    public Personality()
10
+    {
11
+        fTraits = new HashMap<>();
12
+    }
13
+}

+ 12
- 0
backend/src/main/java/model/personnality/Trait.java Parādīt failu

@@ -0,0 +1,12 @@
1
+package model.personnality;
2
+
3
+public class Trait {
4
+
5
+    private String fName;
6
+    private String fDescription;
7
+
8
+    public Trait(String iName, String iDescription){
9
+        fName           = iName;
10
+        fDescription    = iDescription;
11
+    }
12
+}

+ 52
- 0
backend/src/main/java/model/questionnaire/Answer.java Parādīt failu

@@ -0,0 +1,52 @@
1
+package model.questionnaire;
2
+
3
+import com.github.cliftonlabs.json_simple.JsonObject;
4
+import com.github.cliftonlabs.json_simple.Jsonable;
5
+import model.personnality.Trait;
6
+
7
+import java.io.IOException;
8
+import java.io.StringWriter;
9
+import java.io.Writer;
10
+import java.nio.charset.StandardCharsets;
11
+import java.util.UUID;
12
+
13
+public class Answer implements Jsonable {
14
+
15
+    private UUID    fUUID;
16
+    private float   fWeight;
17
+    private Trait   fTrait;
18
+    private String  fDescription;
19
+
20
+
21
+    public Answer(String iDescription, Trait iTrait, float iWeight)
22
+    {
23
+        fUUID           = UUID.randomUUID();    // I feel like I should check this is truly unique among answers
24
+        fWeight         = iWeight;
25
+        fTrait          = iTrait;
26
+        fDescription    = iDescription;
27
+    }
28
+
29
+    public Trait getTrait() { return fTrait; }
30
+    public float getWeight() { return fWeight; }
31
+
32
+
33
+    @Override
34
+    public String toJson() {
35
+        final StringWriter writable = new StringWriter();
36
+        try{
37
+            this.toJson(writable);
38
+        }catch(final IOException caught)
39
+        {
40
+            caught.printStackTrace();
41
+        }
42
+        return writable.toString();
43
+    }
44
+
45
+    @Override
46
+    public void toJson(Writer writable) throws IOException {
47
+        final JsonObject vResult = new JsonObject();
48
+        vResult.put("description", fDescription);
49
+        vResult.put("id", fUUID.toString());
50
+        writable.write(new String(vResult.toJson().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8));
51
+    }
52
+}

+ 42
- 0
backend/src/main/java/model/questionnaire/Question.java Parādīt failu

@@ -0,0 +1,42 @@
1
+package model.questionnaire;
2
+
3
+import com.github.cliftonlabs.json_simple.JsonObject;
4
+import com.github.cliftonlabs.json_simple.Jsonable;
5
+
6
+import java.io.IOException;
7
+import java.io.StringWriter;
8
+import java.io.Writer;
9
+import java.nio.charset.StandardCharsets;
10
+import java.util.List;
11
+
12
+public class Question implements Jsonable {
13
+
14
+    private List<Answer> fAnswers;
15
+    private String fName;
16
+
17
+    public Question(String iName, List<Answer> iAnswers)
18
+    {
19
+        fName = iName;
20
+        fAnswers = iAnswers;
21
+    }
22
+
23
+    @Override
24
+    public String toJson() {
25
+        final StringWriter writable = new StringWriter();
26
+        try{
27
+            this.toJson(writable);
28
+        }catch(final IOException caught)
29
+        {
30
+            caught.printStackTrace();
31
+        }
32
+        return writable.toString();
33
+    }
34
+
35
+    @Override
36
+    public void toJson(Writer writable) throws IOException {
37
+        JsonObject vResult = new JsonObject();
38
+        vResult.put("name", fName);
39
+        vResult.put("answers", fAnswers);
40
+        writable.write(new String(vResult.toJson().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8));
41
+    }
42
+}

+ 31
- 0
backend/src/main/java/model/questionnaire/Questionnaire.java Parādīt failu

@@ -0,0 +1,31 @@
1
+package model.questionnaire;
2
+
3
+import com.github.cliftonlabs.json_simple.JsonObject;
4
+
5
+import java.util.ArrayList;
6
+import java.util.List;
7
+
8
+public class Questionnaire{
9
+
10
+    private static List<Questionnaire> sQuestionnaires = new ArrayList<>();
11
+    private List<Question> fQuestions;
12
+    private String fName;
13
+
14
+    public Questionnaire(String iName, List<Question> iQuestions)
15
+    {
16
+        fName = iName;
17
+        fQuestions = iQuestions;
18
+        sQuestionnaires.add(this);
19
+    }
20
+
21
+    public static Questionnaire getTheOnlyExistingQuestionnaire(){
22
+        return sQuestionnaires.stream().findFirst().get();
23
+    }
24
+
25
+    public JsonObject asJsonObject(){
26
+        JsonObject vResult = new JsonObject();
27
+        vResult.put("name", fName);
28
+        vResult.put("questions",fQuestions);
29
+        return vResult;
30
+    }
31
+}

+ 22
- 0
backend/src/main/java/model/questionnaire/Session.java Parādīt failu

@@ -0,0 +1,22 @@
1
+package model.questionnaire;
2
+
3
+import model.personnality.Personality;
4
+
5
+import java.util.UUID;
6
+
7
+public class Session {
8
+
9
+    private UUID fId;
10
+    private SessionAnswers fAnswers;
11
+    private Personality    fPersonality;
12
+
13
+    public Session(UUID iId){
14
+        fId = iId;
15
+        fAnswers = new SessionAnswers();
16
+        fPersonality = new Personality();
17
+    }
18
+
19
+    public SessionAnswers getSessionAnswers(){ return fAnswers; }
20
+
21
+
22
+}

+ 49
- 0
backend/src/main/java/model/questionnaire/SessionAnswers.java Parādīt failu

@@ -0,0 +1,49 @@
1
+package model.questionnaire;
2
+
3
+import model.personnality.Personality;
4
+import model.personnality.Trait;
5
+
6
+import java.util.HashMap;
7
+
8
+/**
9
+ * Stores answers provided for a session of answers
10
+ */
11
+public class SessionAnswers {
12
+
13
+    private HashMap<Question, Answer> fAnswers;
14
+    private HashMap<Trait, Float> fTraits;
15
+
16
+    public SessionAnswers() {
17
+        fAnswers = new HashMap<>();
18
+    }
19
+
20
+    /**
21
+     * Stores an answer to a question and updates the weight of the related trait.
22
+     * If an answer has already been provided for the question, cancel the weight added by the outdated answer
23
+     * @param iQuestion
24
+     * @param iAnswer
25
+     */
26
+    public void setAnswer(Question iQuestion, Answer iAnswer) {
27
+        // ---------------------------------
28
+        // cancel the weight added by a potential previous answer
29
+        // ---------------------------------
30
+        if(fAnswers.containsKey(iQuestion)) {
31
+            Answer vPreviousAnswer = fAnswers.get(iQuestion);
32
+            Trait vPreviousTrait = vPreviousAnswer.getTrait();
33
+            Float vOutdatedWeight = fTraits.get(vPreviousTrait);
34
+            fTraits.put(vPreviousTrait, vOutdatedWeight - vPreviousAnswer.getWeight());
35
+        }
36
+        // ---------------------------------
37
+        // Store the answer & update the related trait
38
+        // ---------------------------------
39
+        Trait vNewTrait = iAnswer.getTrait();
40
+        Float vNewTraitWeight = iAnswer.getWeight();
41
+        fAnswers.put(iQuestion, iAnswer);
42
+
43
+        if(fTraits.containsKey(vNewTrait))
44
+            vNewTraitWeight += fTraits.get(vNewTrait);
45
+
46
+        fTraits.put(vNewTrait, vNewTraitWeight);
47
+    }
48
+
49
+}

+ 29
- 0
backend/src/test/java/api/ResponseHandlerTest.java Parādīt failu

@@ -0,0 +1,29 @@
1
+package api;
2
+
3
+import com.github.cliftonlabs.json_simple.JsonObject;
4
+import org.junit.jupiter.api.Test;
5
+
6
+import static org.junit.jupiter.api.Assertions.*;
7
+
8
+
9
+class ResponseHandlerTest {
10
+
11
+    @Test
12
+    public void TestGetResponse(){
13
+        ResponseHandler vResponseHandler = new ResponseHandler();
14
+
15
+        String [] vPath = {};
16
+        JsonObject vErrorObject = new JsonObject();
17
+
18
+        vErrorObject.put("error", "Method 'CAFE' not implemented");
19
+        assertEquals(vErrorObject, vResponseHandler.getResponse("CAFE", vPath, "Yo", null));
20
+
21
+        vErrorObject.put("error", "DELETE with 0 subdirectories not implemented");
22
+        assertEquals(vErrorObject, vResponseHandler.getResponse("DELETE", vPath, "Yo", null));
23
+
24
+        vPath = new String[]{"elo", "elo"};
25
+        vErrorObject.put("error", "DELETE with 2 subdirectories not implemented");
26
+        assertEquals(vErrorObject, vResponseHandler.getResponse("DELETE", vPath, "Yo", null));
27
+
28
+    }
29
+}

+ 0
- 38
frontend/src/App.css Parādīt failu

@@ -1,38 +0,0 @@
1
-.App {
2
-  text-align: center;
3
-}
4
-
5
-.App-logo {
6
-  height: 40vmin;
7
-  pointer-events: none;
8
-}
9
-
10
-@media (prefers-reduced-motion: no-preference) {
11
-  .App-logo {
12
-    animation: App-logo-spin infinite 20s linear;
13
-  }
14
-}
15
-
16
-.App-header {
17
-  background-color: #282c34;
18
-  min-height: 100vh;
19
-  display: flex;
20
-  flex-direction: column;
21
-  align-items: center;
22
-  justify-content: center;
23
-  font-size: calc(10px + 2vmin);
24
-  color: white;
25
-}
26
-
27
-.App-link {
28
-  color: #61dafb;
29
-}
30
-
31
-@keyframes App-logo-spin {
32
-  from {
33
-    transform: rotate(0deg);
34
-  }
35
-  to {
36
-    transform: rotate(360deg);
37
-  }
38
-}

+ 20
- 16
frontend/src/App.js Parādīt failu

@@ -1,23 +1,27 @@
1
-import logo from './logo.svg';
2 1
 import './App.css';
2
+import React from 'react';
3
+import Questionnaire from './component/questionnaire';
3 4
 
4 5
 function App() {
6
+  const [questionnaireStarted, onStartQuestionnaire] = React.useState(false);
7
+
5 8
   return (
6
-    <div className="App">
7
-      <header className="App-header">
8
-        <img src={logo} className="App-logo" alt="logo" />
9
-        <p>
10
-          Edit <code>src/App.js</code> and save to reload.
11
-        </p>
12
-        <a
13
-          className="App-link"
14
-          href="https://reactjs.org"
15
-          target="_blank"
16
-          rel="noopener noreferrer"
17
-        >
18
-          Learn React
19
-        </a>
20
-      </header>
9
+    <div>
10
+      <h1>
11
+        Are you an introvert or an extrovert ?
12
+      </h1>
13
+      <div>
14
+        Take this ✨ totally legit test ✨ and find out !
15
+      </div>
16
+      {
17
+        !questionnaireStarted && 
18
+        <div
19
+        onClick={() => onStartQuestionnaire(true)}>
20
+          Start
21
+        </div>
22
+      }
23
+      { questionnaireStarted &&
24
+        <Questionnaire/>}
21 25
     </div>
22 26
   );
23 27
 }

+ 46
- 0
frontend/src/component/question.js Parādīt failu

@@ -0,0 +1,46 @@
1
+import React from 'react';
2
+import url from '../server';
3
+
4
+function Question(props){
5
+    let question = props.questions[props.index];
6
+    const [selectedAnswer, onSelectAnswer] = React.useState(question.answer);
7
+    let question_answers = [];
8
+
9
+    //-------------------------------
10
+    // Build question form
11
+    //-------------------------------
12
+    question.answers.forEach(answer => {
13
+        let dom_id = "answer"+answer.id
14
+        question_answers.push(
15
+            <div key={dom_id}>
16
+                <input name="answer" id={dom_id} type="radio" value={answer.id} defaultChecked={answer.id === selectedAnswer}/>
17
+                <label htmlFor={dom_id}>{answer.description}</label>
18
+            </div>
19
+        );
20
+    });
21
+    
22
+    return (
23
+    <div>
24
+        <div> {question.name} </div>
25
+        <div onChange={(value) => onSelectAnswer(value.target.value)}>
26
+        {question_answers}
27
+        </div>
28
+        <div
29
+            onClick={() => {
30
+                if(props.index === props.questions.length - 1)
31
+                {
32
+                    question.answer = selectedAnswer;
33
+                }
34
+                else
35
+                {
36
+                    question.answer = selectedAnswer;
37
+                    props.moveToQuestion(props.index + 1);
38
+                }
39
+            }}>
40
+                {props.index < props.questions.length -1 ? "Validate" : "Get Result" }
41
+        </div>
42
+    </div>
43
+    );
44
+}
45
+
46
+export default Question;

+ 48
- 0
frontend/src/component/questionnaire.js Parādīt failu

@@ -0,0 +1,48 @@
1
+import React from 'react';
2
+import url from '../server';
3
+import Question from './question';
4
+
5
+function Questionnaire(){
6
+    const [currentIndex, onMoveToIndex] = React.useState(0);
7
+    const [questionnaireDataFetched, onQuestionnaireDataFetched] = React.useState(null);
8
+
9
+    //-------------------------------
10
+    // Fetch questionnaire
11
+    //-------------------------------
12
+    if(null === questionnaireDataFetched)
13
+    {
14
+        fetch(url+"/questionnaire")
15
+            .then(response => response.json())
16
+            .then(result => {
17
+                onQuestionnaireDataFetched(result);
18
+            })
19
+            .catch( e => {
20
+                console.log(e);
21
+            })
22
+    }
23
+
24
+    return (<React.Fragment>
25
+        {
26
+            null === questionnaireDataFetched ?
27
+            <div> Questionnaire is loading </div>
28
+            :
29
+            <Question
30
+                key={"question_"+currentIndex}   //force throw away to ease radio buttons management 
31
+                questions={questionnaireDataFetched.questions}
32
+                index={currentIndex}
33
+                moveToQuestion={onMoveToIndex}/>
34
+        }
35
+        <div>
36
+        {
37
+            currentIndex > 0 ? <div onClick={() => onMoveToIndex(currentIndex-1)}>Previous Question</div> : ''  
38
+        }
39
+        {
40
+            null != questionnaireDataFetched && currentIndex < questionnaireDataFetched.questions.length - 1 && 'answer' in questionnaireDataFetched.questions[currentIndex] && 
41
+            <div onClick={() => onMoveToIndex(currentIndex+1)}>Next Question</div>
42
+        }
43
+        </div>
44
+        </React.Fragment>
45
+    )
46
+}
47
+
48
+export default Questionnaire;

+ 11
- 0
frontend/src/server.js Parādīt failu

@@ -0,0 +1,11 @@
1
+let url = "";
2
+switch(process.env.NODE_ENV) {
3
+  case 'production':
4
+    url = 'https://demisel.space/garage/';
5
+    break;
6
+  case 'development':
7
+  default:
8
+    url = 'http://192.168.0.12:8080';
9
+}
10
+
11
+export default url

Notiek ielāde…
Atcelt
Saglabāt