likes
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import { ideaService } from '../services/ideaService';
|
||||
import { inspirationService } from '../services/inspirationService';
|
||||
|
||||
export const useIdeaStore = defineStore('ideas', () => {
|
||||
const ideas = ref([]);
|
||||
const inspirations = ref([]);
|
||||
const currentIdea = ref(null);
|
||||
const currentInspiration = ref(null); // New state
|
||||
const loading = ref(false);
|
||||
const error = ref(null);
|
||||
const totalIdeas = ref(0);
|
||||
@@ -61,6 +64,25 @@ export const useIdeaStore = defineStore('ideas', () => {
|
||||
}
|
||||
}
|
||||
|
||||
// New action to fetch a single inspiration
|
||||
async function fetchInspiration(id) {
|
||||
loading.value = true;
|
||||
error.value = null;
|
||||
currentInspiration.value = null;
|
||||
try {
|
||||
const response = await inspirationService.getInspiration(id);
|
||||
currentInspiration.value = response.data;
|
||||
return response.data;
|
||||
} catch (err) {
|
||||
console.error('Error fetching inspiration:', err);
|
||||
error.value = err.response?.data?.detail || 'Failed to fetch inspiration';
|
||||
return null;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function updateIdea(id, data) {
|
||||
loading.value = true;
|
||||
error.value = null;
|
||||
@@ -143,9 +165,85 @@ export const useIdeaStore = defineStore('ideas', () => {
|
||||
}
|
||||
}
|
||||
|
||||
// --- Inspirations ---
|
||||
async function fetchInspirations(limit = 20, offset = 0) {
|
||||
loading.value = true;
|
||||
try {
|
||||
const response = await inspirationService.getInspirations(limit, offset);
|
||||
inspirations.value = response.data.inspirations || response.data;
|
||||
} catch (err) {
|
||||
console.error('Error fetching inspirations:', err);
|
||||
error.value = err.response?.data?.detail || 'Failed to fetch inspirations';
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function createInspiration(data) {
|
||||
loading.value = true;
|
||||
try {
|
||||
await inspirationService.createInspiration(data);
|
||||
await fetchInspirations();
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.error('Error creating inspiration:', err);
|
||||
error.value = err.response?.data?.detail || 'Failed to create inspiration';
|
||||
return false;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function updateInspiration(id, data) {
|
||||
loading.value = true;
|
||||
try {
|
||||
await inspirationService.updateInspiration(id, data);
|
||||
await fetchInspirations();
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.error('Error updating inspiration:', err);
|
||||
error.value = err.response?.data?.detail || 'Failed to update inspiration';
|
||||
return false;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteInspiration(id) {
|
||||
loading.value = true;
|
||||
try {
|
||||
await inspirationService.deleteInspiration(id);
|
||||
await fetchInspirations();
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.error('Error deleting inspiration:', err);
|
||||
error.value = err.response?.data?.detail || 'Failed to delete inspiration';
|
||||
return false;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function completeInspiration(id) {
|
||||
loading.value = true;
|
||||
try {
|
||||
await inspirationService.completeInspiration(id);
|
||||
await fetchInspirations();
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.error('Error completing inspiration:', err);
|
||||
error.value = err.response?.data?.detail || 'Failed to complete inspiration';
|
||||
return false;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
ideas,
|
||||
inspirations,
|
||||
currentIdea,
|
||||
currentInspiration,
|
||||
loading,
|
||||
error,
|
||||
totalIdeas,
|
||||
@@ -156,6 +254,12 @@ export const useIdeaStore = defineStore('ideas', () => {
|
||||
deleteIdea,
|
||||
addGenerationToIdea,
|
||||
removeGenerationFromIdea,
|
||||
fetchIdeaGenerations
|
||||
fetchIdeaGenerations,
|
||||
fetchInspirations,
|
||||
createInspiration,
|
||||
updateInspiration,
|
||||
deleteInspiration,
|
||||
completeInspiration,
|
||||
fetchInspiration
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user