Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/components/tutor/ThirdStep.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ const props = defineProps<{
action: () => {};
actionText?: string;
disabled: boolean;
updateSyllabus: () => void;
updateSyllabus: (content: string) => void;
restart: () => void;
updateSyllabusInDB: () => void;
}>();

const isEditable: Ref<boolean> = ref(false);
Expand All @@ -26,9 +27,17 @@ const toggleFeedback = async () => {
enableFeedback.value = !enableFeedback.value;
};

const handleTextEdit = (event, index) => {
const handleTextEdit = (event) => {
const newValue = event.target.innerText;
props.updateSyllabus(index, newValue);
props.updateSyllabus(newValue);
};

const handleSyllabusEdition = () => {
if (isEditable.value) {
// Save the edited syllabus
props.updateSyllabusInDB();
}
isEditable.value = !isEditable.value;
};
</script>
<template>
Expand All @@ -40,7 +49,7 @@ const handleTextEdit = (event, index) => {
<!-- syllabus -->

<div class="is-flex is-flex-direction-column">
<button class="button is-white ml-auto" @click="isEditable = !isEditable">
<button class="button is-white ml-auto" @click="handleSyllabusEdition">
<span class="icon is-small mr-2">
<EditIcon />
</span>
Expand All @@ -54,7 +63,7 @@ const handleTextEdit = (event, index) => {
class="syllabus content"
v-if="syllabus?.content"
v-html="marked.parse(syllabus?.content)"
@blur="handleTextEdit($event, index)"
@blur="handleTextEdit($event)"
@click="isEditable = true"
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/stores/featureFlip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const useFeatureFlipStore = defineStore('featureFlip', () => {
};

const isWorkshopFeatureEnabled = () => {
return isDevEnvironment || window.location.href.includes('workshop');
return isDevEnvironment;
};

return {
Expand Down
18 changes: 15 additions & 3 deletions src/stores/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,24 @@ export const useMetricsStore = defineStore('metrics', () => {
return;
}

if (!isInPage('q-and-a')) {
let storageKey;

if (isInPage('q-and-a')) {
storageKey = 'chatMessageId';
}
if (isInPage('tutor')) {
storageKey = 'tutorMessageId';
}
if (isInPage('search')) {
storageKey = 'searchMessageId';
}

if (!storageKey) {
return;
}
// get message id from storage
const messageId = localStorage.getItem('chatMessageId');

// get message id from storage
const messageId = localStorage.getItem(storageKey);
if (!messageId || !docId) {
return;
}
Expand Down
8 changes: 6 additions & 2 deletions src/stores/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ export const useSearchStore = defineStore('search', () => {
];
const [sdgsFromQuery, { data, status }] = await Promise.all(promises);

sdgsQuery.value = sdgsFromQuery;
sdgsQuery.value = sdgsFromQuery as string[];

isFetchingSources.value = false;
searchResults.value = data;
searchResults.value = data.length ? data : data.docs;

if (data?.search_message_id) {
localStorage.setItem('searchMessageId', data.search_message_id);
}

if (status === 206) {
hasPartialResult.value = true;
Expand Down
30 changes: 27 additions & 3 deletions src/stores/tutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ export const useTutorStore = defineStore('tutor', () => {
summaries.value[index] = content;
};

const updateSyllabus = (index, content) => {
syllabi.value[index] = content;
const updateSyllabus = (content: string) => {
if (!syllabi.value) {
return;
}
syllabi.value = { ...syllabi.value, content };
};

const syllabusLanguage: Ref<string> = ref(i18n.global.locale.value);
Expand Down Expand Up @@ -321,6 +324,26 @@ export const useTutorStore = defineStore('tutor', () => {
}
const docxContent = await convertMarkdownToDocx(syllabi.value.content);
downloadDocx(docxContent, 'syllabus.docx');
try {
await postAxios('/metric/syllabus_downloaded');
} catch (error) {
console.error('Error during metrics update:', error);
}
};

const updateSyllabusInDB = async () => {
if (!syllabi.value || !syllabi.value.content) {
console.error('No syllabi available for download');
return;
}

try {
await postAxios('/tutor/syllabus/user_update', {
syllabus: syllabi.value.content
});
} catch (error) {
console.error('Error during syllabus update:', error);
}
};

return {
Expand Down Expand Up @@ -359,6 +382,7 @@ export const useTutorStore = defineStore('tutor', () => {
summaries,
newFilesToSearch,
stopAction,
updateSyllabus
updateSyllabus,
updateSyllabusInDB
};
});
1 change: 1 addition & 0 deletions src/views/TutorPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const stepToAction: Record<1 | 2 | 3 | 4, (arg?: any) => Promise<void>> = {
:giveFeedback="store.giveFeedback"
:action="stepToAction[4]"
:restart="store.restart"
:updateSyllabusInDB="store.updateSyllabusInDB"
/>
</div>
</div>
Expand Down
Loading