Skip to content

Commit f7968af

Browse files
feat(tutor): connects tutor to API and data
1 parent 5350ae2 commit f7968af

File tree

5 files changed

+89
-15
lines changed

5 files changed

+89
-15
lines changed

src/components/tutor/FirstStep.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script setup lang="ts">
22
import { ref } from 'vue';
3-
defineProps<{
3+
const props = defineProps<{
44
disabled?: boolean;
5+
addFile?: (e: Event) => void;
56
}>();
67
const inputGroupLength = ref(1);
78
@@ -22,6 +23,7 @@ const appendNewInputFile = () => {
2223
input.type = 'file';
2324
input.className = 'input';
2425
input.placeholder = 'Enter the name of the file';
26+
input.onchange = (e) => props.addFile(e);
2527
div.appendChild(input);
2628
div.appendChild(deleteButton);
2729
inputGroup.appendChild(div);
@@ -52,6 +54,7 @@ const removeLastInputFile = () => {
5254
type="text"
5355
id="cursus-title"
5456
:placeholder="$t('tutor.firstStep.cursusTitlePlaceholder')"
57+
@change="(e) => addFile(e)"
5558
/>
5659
</div>
5760
<div class="description">

src/components/tutor/SecondStep.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
<script setup lang="ts">
2-
import { ref } from 'vue';
32
import { type Document } from '@/types';
43
import CardSimpleComponent from '@/components/CardSimpleComponent.vue';
5-
import data from './mockedSearchResult.json';
64
defineProps<{
5+
sources?: Document[];
76
disabled?: boolean;
87
visible?: boolean;
98
}>();
10-
11-
const sources = ref<Document[]>(data);
129
</script>
1310
<template>
1411
<div class="wrapper" :class="{ disabled: disabled, visible: visible }">

src/components/tutor/ThirdStep.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script setup lang="ts">
22
import { marked } from 'marked';
3-
import { syllabus } from './mockedSyllabus.js';
43
defineProps<{
54
visible?: boolean;
5+
syllabus?: string;
66
}>();
77
</script>
88
<template>
@@ -39,6 +39,7 @@ defineProps<{
3939
border: 1px solid var(--neutral-20);
4040
border-radius: 0.5rem;
4141
min-height: 10rem;
42+
max-width: 80rem;
4243
overflow-y: auto;
4344
overflow-x: auto;
4445
background-color: var(--neutral-10);

src/stores/tutor.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { defineStore } from 'pinia';
2+
import { type Ref, ref } from 'vue';
3+
import { type Document } from '@/types';
4+
import { postAxios } from '@/utils/fetch';
5+
6+
export type TutorSearch = {
7+
extracts: { original_document: string; summary: string; themes: string[] }[];
8+
nb_results: number;
9+
documents: Document[];
10+
};
11+
12+
type TutorSyllabus = {
13+
syllabus: string;
14+
documents: Document[];
15+
};
16+
// TODO: :arrow-up: move this to types
17+
18+
export const useTutorStore = defineStore('tutor', () => {
19+
const tutorSearch: Ref<TutorSearch | null> = ref(null);
20+
21+
const retrieveTutorSearch = async (arg: FormData): Promise<TutorSearch> => {
22+
const resp = await postAxios('/tutor/search', arg, {
23+
headers: { 'content-type': 'multipart/form-data' }
24+
});
25+
26+
tutorSearch.value = resp.data;
27+
28+
return resp.data;
29+
};
30+
31+
const retrieveSyllabus = async (): Promise<TutorSyllabus> => {
32+
if (!tutorSearch.value) {
33+
throw new Error('Body is empty');
34+
}
35+
const resp = await postAxios('/tutor/syllabus', {
36+
...tutorSearch.value
37+
});
38+
return resp.data;
39+
};
40+
41+
return { retrieveTutorSearch, retrieveSyllabus };
42+
});

src/views/TutorPage.vue

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,67 @@ import FirstStep from '@/components/tutor/FirstStep.vue';
44
import SecondStep from '@/components/tutor/SecondStep.vue';
55
import ThirdStep from '@/components/tutor/ThirdStep.vue';
66
import StepsIndicator from '@/components/tutor/StepsIndicator.vue';
7+
import { useTutorStore, type TutorSearch } from '@/stores/tutor';
78
9+
const store = useTutorStore();
10+
11+
const files: Ref<File[]> = ref([]);
12+
const response: Ref<TutorSearch | null> = ref(null);
13+
const syllabus = ref<string>('');
814
const step = ref(1);
9-
const setStep = (val) => {
10-
step.value = val;
15+
16+
const formData = new FormData();
17+
18+
const addFile = (e: any) => {
19+
formData.append('files', e.target.files[0]);
20+
files.value.push(e.target.files);
1121
};
1222
13-
const handleSearch = () => {
14-
console.log('handle search');
23+
const handleSearch = async () => {
24+
response.value = null;
25+
26+
if (!files.value.length) {
27+
return;
28+
}
29+
30+
const resp = await store.retrieveTutorSearch(formData);
31+
32+
response.value = resp;
1533
step.value = step.value + 1;
1634
};
1735
18-
const handleCreateSyllabus = () => {
19-
console.log('create syllabus');
36+
const setStep = (val) => {
37+
step.value = val;
38+
};
39+
40+
const handleCreateSyllabus = async () => {
41+
const newSylalbus = await store.retrieveSyllabus();
42+
syllabus.value = newSylalbus.syllabus;
2043
step.value = step.value + 1;
2144
};
2245
2346
const stepToAction = {
2447
1: handleSearch,
2548
2: handleCreateSyllabus
2649
};
50+
51+
// TODO: add a modal with waiting info
52+
// button to export syllabus
2753
</script>
2854
<template>
2955
<div class="content-centered-wrapper">
3056
<StepsIndicator :step="step" :setStep="setStep" :stepsLength="3" />
3157
<div class="layout-flex">
3258
<div class="flex-wrap" :class="{ shrink: step === 3 }">
33-
<FirstStep data-test="fist-step" :disabled="step > 1" v-if="step >= 1" />
34-
<SecondStep data-test="second-step" :disabled="step > 2" :visible="step >= 2" />
59+
<FirstStep data-test="fist-step" :disabled="step > 1" v-if="step >= 1" :addFile="addFile" />
60+
<SecondStep
61+
data-test="second-step"
62+
:disabled="step > 2"
63+
:visible="step >= 2 && response"
64+
:sources="response ? response?.documents : null"
65+
/>
3566
</div>
36-
<ThirdStep data-test="third-step" :visible="step >= 3" />
67+
<ThirdStep data-test="third-step" :visible="step >= 3 && syllabus" :syllabus="syllabus" />
3768
</div>
3869
<div class="actions">
3970
<button class="button" v-if="step > 1" @click="step = step - 1">previous</button>

0 commit comments

Comments
 (0)