more styles, functionality complete, some bugs tho
This commit is contained in:
parent
84d80a6965
commit
ca5cfa7215
8 changed files with 61 additions and 105 deletions
BIN
public/assets/fonts/SF-Pro-Text-Regular.otf
Executable file
BIN
public/assets/fonts/SF-Pro-Text-Regular.otf
Executable file
Binary file not shown.
|
|
@ -26,22 +26,20 @@ export const psychForm = {
|
|||
|
||||
}
|
||||
|
||||
/* Dummy algo for demo purposes, simply takes average of fields. */
|
||||
export const psychAlgo = (form, res) => {
|
||||
|
||||
// algo: () => {
|
||||
const vals = [];
|
||||
|
||||
// const values = [];
|
||||
form.steps.forEach(s => {
|
||||
|
||||
// steps.forEach(s => {
|
||||
s.fields.forEach(f => {
|
||||
|
||||
// s.fields.forEach(f => {
|
||||
vals.push(f.value);
|
||||
|
||||
// values.push(f.value);
|
||||
});
|
||||
|
||||
// });
|
||||
});
|
||||
|
||||
// });
|
||||
|
||||
// const sum = values.reduce((p, c) => p + c, 0);
|
||||
|
||||
// return sum / values.length;
|
||||
// }
|
||||
res.value = Math.floor(vals.reduce((a, b) => a + b) / vals.length);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,9 +13,16 @@ const Form =
|
|||
const curr = Vue.ref(0);
|
||||
|
||||
function next() {
|
||||
curr.value < props.steps.length - 1 ?
|
||||
curr.value += 1 :
|
||||
|
||||
console.log(props.steps);
|
||||
|
||||
if (curr.value > props.steps.length - 2) {
|
||||
props.submit();
|
||||
return;
|
||||
}
|
||||
|
||||
curr.value += 1;
|
||||
|
||||
}
|
||||
|
||||
return { curr, next };
|
||||
|
|
@ -26,20 +33,15 @@ const Form =
|
|||
|
||||
<Step v-bind="steps[curr]" />
|
||||
|
||||
<button class="next-button form-button button" @click="next">Next</button>
|
||||
<button
|
||||
class="next-button form-button button"
|
||||
@click="next"
|
||||
>
|
||||
Next
|
||||
</button>
|
||||
|
||||
</div>
|
||||
`
|
||||
}
|
||||
|
||||
export default Form;
|
||||
|
||||
/*
|
||||
|
||||
So we store the results of the form inside the templete itself.
|
||||
|
||||
Is this really a good idea?
|
||||
|
||||
Why not just have a mapping that we fill out as the form progresses?
|
||||
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
import { psychForm } from "../assets/forms.js";
|
||||
import { psychForm, psychAlgo } from "../assets/forms.js";
|
||||
|
||||
import Form from "./form.js";
|
||||
import Range from "./range.js";
|
||||
|
||||
|
||||
const Main =
|
||||
{
|
||||
components: {
|
||||
|
|
@ -12,6 +11,7 @@ const Main =
|
|||
|
||||
setup()
|
||||
{
|
||||
const res = Vue.ref(0);
|
||||
const state = Vue.ref(0);
|
||||
|
||||
function showForm() {
|
||||
|
|
@ -19,14 +19,15 @@ const Main =
|
|||
}
|
||||
|
||||
function submit() {
|
||||
psychAlgo(psychForm, res); /* pass by ref flex ;) */
|
||||
state.value = 2;
|
||||
}
|
||||
|
||||
return { psychForm, state, showForm, submit };
|
||||
return { psychForm, state, showForm, submit, res };
|
||||
},
|
||||
|
||||
template: `
|
||||
<div>
|
||||
<div id="main">
|
||||
|
||||
<div v-if="state == 0">
|
||||
|
||||
|
|
@ -40,17 +41,10 @@ const Main =
|
|||
|
||||
<Form v-else-if="state == 1" v-bind="psychForm" :submit="submit" />
|
||||
|
||||
<div v-else>Result!</div>
|
||||
<div class="result" v-else>{{ res }}</div>
|
||||
|
||||
</div>
|
||||
`
|
||||
}
|
||||
|
||||
export default Main;
|
||||
|
||||
/*
|
||||
|
||||
Notes...
|
||||
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -8,28 +8,28 @@ const Range =
|
|||
|
||||
setup(props)
|
||||
{
|
||||
const value = Vue.ref(50);
|
||||
const ref = Vue.ref(50);
|
||||
|
||||
Vue.watch(value, (c, _p) => {
|
||||
Vue.watch(ref, (c, _p) => {
|
||||
|
||||
props.field.value = c;
|
||||
props.field.value = parseInt(c);
|
||||
|
||||
});
|
||||
|
||||
return { value };
|
||||
return { ref };
|
||||
},
|
||||
|
||||
template: `
|
||||
<div>
|
||||
<div class="range">
|
||||
|
||||
Range Input!
|
||||
<div>{{ ref }}</div>
|
||||
|
||||
<input
|
||||
v-model="value"
|
||||
v-model="ref"
|
||||
type="range"
|
||||
min="0"
|
||||
max="100"
|
||||
value="50"
|
||||
min="0"
|
||||
max="100"
|
||||
value="50"
|
||||
step="1"
|
||||
>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
const Result =
|
||||
{
|
||||
props: ["form"],
|
||||
|
||||
setup(props)
|
||||
{
|
||||
return { };
|
||||
},
|
||||
|
||||
template: `
|
||||
<div>
|
||||
|
||||
Result!
|
||||
|
||||
</div>
|
||||
`
|
||||
}
|
||||
|
||||
export default Result;
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Takes in data from the form and displays it.
|
||||
|
||||
Of course, all forms will have a different algo to process their data.
|
||||
|
||||
So each form can supply it's own algo.
|
||||
|
||||
But algos are required to return an int.
|
||||
|
||||
So the results page can render that int in it's own way.
|
||||
|
||||
*/
|
||||
|
|
@ -18,24 +18,10 @@ const Step =
|
|||
|
||||
<div class="prompt">{{ prompt }}</div>
|
||||
|
||||
<div class="fields" v-for="field in fields">
|
||||
|
||||
<Range :field="field" />
|
||||
|
||||
</div>
|
||||
<Range v-for="field in fields" :field=field />
|
||||
|
||||
</div>
|
||||
`
|
||||
}
|
||||
|
||||
export default Step;
|
||||
|
||||
/*
|
||||
|
||||
Single step of the form, can have multiple fields.
|
||||
|
||||
There is only one type of field (range), but could be more.
|
||||
|
||||
Were gonna pass in the data object to the field.
|
||||
|
||||
*/
|
||||
|
|
@ -1,3 +1,8 @@
|
|||
@font-face {
|
||||
font-family: "Default";
|
||||
src: url("assets/fonts/SF-Pro-Text-Regular.otf");
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Rounded";
|
||||
src: url("assets/fonts/SF-Compact-Rounded-Bold.otf");
|
||||
|
|
@ -7,6 +12,7 @@ html, body {
|
|||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: #EBEBEB;
|
||||
font-family: "Default";
|
||||
}
|
||||
|
||||
#main {
|
||||
|
|
@ -18,9 +24,8 @@ html, body {
|
|||
}
|
||||
|
||||
.form {
|
||||
width: 50vw;
|
||||
height: 50vh;
|
||||
background-color: white;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
|
|
@ -30,26 +35,32 @@ html, body {
|
|||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: lightgray;
|
||||
}
|
||||
|
||||
.prompt {
|
||||
top: 0;
|
||||
left: 0;
|
||||
position: absolute;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.fields {
|
||||
.range {
|
||||
font-family: "Rounded";
|
||||
}
|
||||
|
||||
.result {
|
||||
font-size: 60px;
|
||||
font-family: "Rounded";
|
||||
}
|
||||
|
||||
.button {
|
||||
border: none;
|
||||
outline: none;
|
||||
text-decoration: none;
|
||||
font-family: "Rounded";
|
||||
}
|
||||
|
||||
.next-button {
|
||||
font-family: "Rounded";
|
||||
background-color: #B7B7B7;
|
||||
padding: 10px 20px;
|
||||
border-radius: 20px;
|
||||
|
|
@ -61,7 +72,8 @@ html, body {
|
|||
}
|
||||
|
||||
.form-button {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
position: absolute;
|
||||
margin: 20px;
|
||||
}
|
||||
Loading…
Reference in a new issue