first implementation
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { api } from '@/services/api'
|
||||
|
||||
export interface Topic {
|
||||
id: string
|
||||
name: string
|
||||
description: string
|
||||
category: string
|
||||
}
|
||||
|
||||
export interface SourceReference {
|
||||
bookTitle: string
|
||||
page: number | null
|
||||
}
|
||||
|
||||
export interface TopicSummary {
|
||||
topicId: string
|
||||
topicName: string
|
||||
summary: string
|
||||
sources: SourceReference[]
|
||||
generatedAt: string
|
||||
}
|
||||
|
||||
export const useTopicStore = defineStore('topics', () => {
|
||||
const topics = ref<Topic[]>([])
|
||||
const activeSummary = ref<TopicSummary | null>(null)
|
||||
const activeSummaryTopicId = ref<string | null>(null)
|
||||
const loading = ref(false)
|
||||
const summaryLoading = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
async function fetchTopics() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const response = await api.get<Topic[]>('/topics')
|
||||
topics.value = response.data
|
||||
} catch (err: any) {
|
||||
error.value = err.message
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function generateSummary(topicId: string): Promise<TopicSummary | null> {
|
||||
summaryLoading.value = true
|
||||
activeSummaryTopicId.value = topicId
|
||||
activeSummary.value = null
|
||||
error.value = null
|
||||
try {
|
||||
const response = await api.post<TopicSummary>(`/topics/${topicId}/summary`)
|
||||
activeSummary.value = response.data
|
||||
return response.data
|
||||
} catch (err: any) {
|
||||
error.value = err.message
|
||||
return null
|
||||
} finally {
|
||||
summaryLoading.value = false
|
||||
activeSummaryTopicId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
topics,
|
||||
activeSummary,
|
||||
activeSummaryTopicId,
|
||||
loading,
|
||||
summaryLoading,
|
||||
error,
|
||||
fetchTopics,
|
||||
generateSummary
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user