kjdskjk
This commit is contained in:
@@ -1,12 +1,76 @@
|
||||
import { ref } from 'vue';
|
||||
import { useCampaignService } from '~/services/Campaign.js';
|
||||
import Server from './Server';
|
||||
|
||||
const ShowContent = ref(false);
|
||||
|
||||
const TotalNotes = ref([]); // Full note data
|
||||
const CurrentNotes = ref([]); // Current opened note keys
|
||||
|
||||
function SetShowContent(value) {
|
||||
ShowContent.value = value;
|
||||
}
|
||||
|
||||
function PushNote(note){
|
||||
CurrentNotes.value = CurrentNotes.value.filter((currentNote) => {
|
||||
return currentNote.key !== note.key;
|
||||
});
|
||||
CurrentNotes.value.push(note.key);
|
||||
}
|
||||
|
||||
function DeleteNote(key){
|
||||
CurrentNotes.value = CurrentNotes.value.filter((k) => {
|
||||
return k !== key;
|
||||
});
|
||||
}
|
||||
|
||||
async function FetchCampaignNotes() {
|
||||
// First we get campaign info
|
||||
const { Campaign } = useCampaignService();
|
||||
const campaignId = Campaign.value?._id ?? Campaign.value?.id ?? null;
|
||||
|
||||
if (!campaignId) {
|
||||
TotalNotes.value = [];
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await Server().get('/note/list', {
|
||||
params: {
|
||||
campaign: campaignId
|
||||
}
|
||||
});
|
||||
|
||||
if (response.data.status !== 'ok') {
|
||||
// TODO: ERROR
|
||||
return;
|
||||
}
|
||||
TotalNotes.value = response.data.notes.map((note) => {
|
||||
return {
|
||||
key: note._id,
|
||||
title: note.title,
|
||||
text: note.content ?? '',
|
||||
date: note.date
|
||||
};
|
||||
});
|
||||
} catch (error) {
|
||||
// TODO: ERROR
|
||||
console.error(error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function GetNoteByName(name){
|
||||
return TotalNotes.value.find(note => note.title == name);
|
||||
}
|
||||
|
||||
export {
|
||||
ShowContent,
|
||||
SetShowContent
|
||||
SetShowContent,
|
||||
CurrentNotes,
|
||||
FetchCampaignNotes,
|
||||
TotalNotes,
|
||||
PushNote,
|
||||
DeleteNote,
|
||||
GetNoteByName
|
||||
}
|
||||
Reference in New Issue
Block a user