This commit is contained in:
@@ -4,7 +4,6 @@ import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
|
|||||||
import { useCampaignService } from '~/services/Campaign.js';
|
import { useCampaignService } from '~/services/Campaign.js';
|
||||||
import { emitter } from '~/services/Emitter';
|
import { emitter } from '~/services/Emitter';
|
||||||
import Server from '~/services/Server';
|
import Server from '~/services/Server';
|
||||||
import { CreateWindow } from '~/services/Windows';
|
|
||||||
|
|
||||||
const { Campaign } = useCampaignService();
|
const { Campaign } = useCampaignService();
|
||||||
const notes = ref([]);
|
const notes = ref([]);
|
||||||
@@ -64,14 +63,31 @@ function toggleSidebar() {
|
|||||||
sidebarCollapsed.value = !sidebarCollapsed.value;
|
sidebarCollapsed.value = !sidebarCollapsed.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function openCreateNoteWindow() {
|
async function createNote() {
|
||||||
if (!Campaign.value) {
|
if (!Campaign.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateWindow('create_note');
|
const campaignId = Campaign.value?._id
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await Server().post('/note/create', {
|
||||||
|
title: 'New note',
|
||||||
|
content: "",
|
||||||
|
campaign: campaignId
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.data.status !== 'ok') {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emitter.emit('note-created', response.data.note);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function openNote(note) {
|
function openNote(note) {
|
||||||
emitter.emit('push-note', note);
|
emitter.emit('push-note', note);
|
||||||
}
|
}
|
||||||
@@ -136,7 +152,7 @@ watch(Campaign, () => {
|
|||||||
<button
|
<button
|
||||||
class="sidebar-action"
|
class="sidebar-action"
|
||||||
type="button"
|
type="button"
|
||||||
@click="openCreateNoteWindow"
|
@click="createNote"
|
||||||
:disabled="!Campaign"
|
:disabled="!Campaign"
|
||||||
title="New note"
|
title="New note"
|
||||||
aria-label="New note"
|
aria-label="New note"
|
||||||
|
|||||||
@@ -10,12 +10,30 @@ const campaignName = computed(() => {
|
|||||||
return Campaign.value?.name ?? 'Campaign';
|
return Campaign.value?.name ?? 'Campaign';
|
||||||
});
|
});
|
||||||
|
|
||||||
function openCreateNoteWindow() {
|
async function createNote() {
|
||||||
if (!Campaign.value) {
|
if (!Campaign.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateWindow('create_note');
|
const campaignId = Campaign.value?._id
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await Server().post('/note/create', {
|
||||||
|
title: 'New note',
|
||||||
|
content: content.value,
|
||||||
|
campaign: campaignId
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.data.status !== 'ok') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
emitter.emit('note-created', response.data.note);
|
||||||
|
} catch (err) {
|
||||||
|
error.value = 'Unable to create note.';
|
||||||
|
} finally {
|
||||||
|
isSaving.value = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function exitToMainMenu() {
|
function exitToMainMenu() {
|
||||||
@@ -42,7 +60,7 @@ function exitToMainMenu() {
|
|||||||
<img class="top-bar-button-icon" src="/icons/iconoir/regular/nav-arrow-left.svg" alt="" aria-hidden="true">
|
<img class="top-bar-button-icon" src="/icons/iconoir/regular/nav-arrow-left.svg" alt="" aria-hidden="true">
|
||||||
<span>Main Menu</span>
|
<span>Main Menu</span>
|
||||||
</button>
|
</button>
|
||||||
<button class="note-button sound-click" type="button" @click="openCreateNoteWindow" :disabled="!Campaign">
|
<button class="note-button sound-click" type="button" @click="createNote" :disabled="!Campaign">
|
||||||
<img class="note-button-icon" src="/icons/iconoir/regular/plus.svg" alt="" aria-hidden="true">
|
<img class="note-button-icon" src="/icons/iconoir/regular/plus.svg" alt="" aria-hidden="true">
|
||||||
<span>New Note</span>
|
<span>New Note</span>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ onMounted(() => {
|
|||||||
|
|
||||||
.roll-btn {
|
.roll-btn {
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
margin-right: 4px;
|
margin-right: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
@@ -1,150 +0,0 @@
|
|||||||
<script setup>
|
|
||||||
import { computed, onMounted, ref } from 'vue';
|
|
||||||
import { SetupHandle, SetSize, ResetPosition, Top, ClearWindow } from '@/services/Windows';
|
|
||||||
import WindowHandle from './partials/WindowHandle.vue';
|
|
||||||
import Server from '~/services/Server';
|
|
||||||
import { emitter } from '~/services/Emitter';
|
|
||||||
import { useCampaignService } from '~/services/Campaign';
|
|
||||||
|
|
||||||
const handle = ref(null);
|
|
||||||
const wrapper = ref(null);
|
|
||||||
|
|
||||||
const props = defineProps(['data']);
|
|
||||||
const data = props.data;
|
|
||||||
|
|
||||||
const { Campaign } = useCampaignService();
|
|
||||||
|
|
||||||
const id = data.id;
|
|
||||||
const title = ref('');
|
|
||||||
const content = ref('');
|
|
||||||
const isSaving = ref(false);
|
|
||||||
const error = ref('');
|
|
||||||
|
|
||||||
const campaignId = computed(() => {
|
|
||||||
return Campaign.value?._id ?? Campaign.value?.id ?? null;
|
|
||||||
});
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
Top(wrapper);
|
|
||||||
SetupHandle(id, handle);
|
|
||||||
SetSize(id, { width: 640, height: 520 });
|
|
||||||
ResetPosition(id, "center");
|
|
||||||
});
|
|
||||||
|
|
||||||
async function createNote() {
|
|
||||||
if (!campaignId.value || isSaving.value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
isSaving.value = true;
|
|
||||||
error.value = '';
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await Server().post('/note/create', {
|
|
||||||
title: title.value.trim() || 'Untitled Note',
|
|
||||||
content: content.value,
|
|
||||||
campaign: campaignId.value
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.data.status !== 'ok') {
|
|
||||||
error.value = response.data.msg ?? 'Unable to create note.';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
emitter.emit('note-created', response.data.note);
|
|
||||||
ClearWindow({ id });
|
|
||||||
} catch (err) {
|
|
||||||
error.value = 'Unable to create note.';
|
|
||||||
} finally {
|
|
||||||
isSaving.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="window-wrapper" :id="'window-wrapper-' + id" ref="wrapper">
|
|
||||||
<WindowHandle :window="id" ref="handle"></WindowHandle>
|
|
||||||
|
|
||||||
<div class="body">
|
|
||||||
<form @submit.prevent="createNote">
|
|
||||||
<div class="form-field">
|
|
||||||
<label>Title</label>
|
|
||||||
<input v-model="title" type="text" name="noteTitle" placeholder="Enter a note title" autocomplete="off">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-field stacked">
|
|
||||||
<label>Content</label>
|
|
||||||
<textarea v-model="content" name="noteContent" placeholder="Write your note here"></textarea>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="error" class="form-error">
|
|
||||||
{{ error }}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-actions">
|
|
||||||
<button class="btn-primary sound-click" :disabled="isSaving">
|
|
||||||
{{ isSaving ? 'Creating...' : 'Create Note' }}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.window-wrapper {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.body {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
form {
|
|
||||||
margin: 10px;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-field {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-field > * {
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.stacked {
|
|
||||||
align-items: stretch;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
label {
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
textarea {
|
|
||||||
min-height: 300px;
|
|
||||||
resize: vertical;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-error {
|
|
||||||
color: #9e2a2b;
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-actions {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-actions button {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -27,7 +27,7 @@ const GetWidget = (type, name) => {
|
|||||||
const marker = new Marked();
|
const marker = new Marked();
|
||||||
|
|
||||||
const extension = {
|
const extension = {
|
||||||
name: "something",
|
name: "widget",
|
||||||
level: "block",
|
level: "block",
|
||||||
|
|
||||||
tokenizer(src) {
|
tokenizer(src) {
|
||||||
@@ -37,7 +37,7 @@ const extension = {
|
|||||||
if (!match) return;
|
if (!match) return;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: "something",
|
type: "widget",
|
||||||
raw: match[0],
|
raw: match[0],
|
||||||
name: match[1],
|
name: match[1],
|
||||||
text: match[2],
|
text: match[2],
|
||||||
@@ -50,7 +50,7 @@ const extension = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const inlineExtension = {
|
const inlineExtension = {
|
||||||
name: "something_inline",
|
name: "widget_inline",
|
||||||
level: "inline",
|
level: "inline",
|
||||||
start(src) {
|
start(src) {
|
||||||
return src.indexOf("@");
|
return src.indexOf("@");
|
||||||
@@ -62,7 +62,7 @@ const inlineExtension = {
|
|||||||
if (!match) return;
|
if (!match) return;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: "something_inline",
|
type: "widget_inline",
|
||||||
raw: match[0],
|
raw: match[0],
|
||||||
name: match[1],
|
name: match[1],
|
||||||
text: match[2],
|
text: match[2],
|
||||||
@@ -74,8 +74,32 @@ const inlineExtension = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const linkExtension = {
|
||||||
|
name: "link_to",
|
||||||
|
level: "inline",
|
||||||
|
start(src) {
|
||||||
|
return src.indexOf("[[");
|
||||||
|
},
|
||||||
|
|
||||||
|
tokenizer(src) {
|
||||||
|
const rule = /^\[\[([^\n]*)\]\]/;
|
||||||
|
const match = rule.exec(src);
|
||||||
|
if (!match) return;
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: "link_to",
|
||||||
|
raw: match[0],
|
||||||
|
link: match[1],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
renderer(token) {
|
||||||
|
return `<span class="vue-link" data-href="${token.link}"></span>`;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
marker.use({
|
marker.use({
|
||||||
extensions: [extension, inlineExtension],
|
extensions: [extension, inlineExtension, linkExtension],
|
||||||
});
|
});
|
||||||
|
|
||||||
function ParseMarkdown(source) {
|
function ParseMarkdown(source) {
|
||||||
|
|||||||
@@ -34,12 +34,6 @@ const defWindows = {
|
|||||||
component: () => import('~/components/windows/CreateCampaignWindow.vue'),
|
component: () => import('~/components/windows/CreateCampaignWindow.vue'),
|
||||||
close: () => ClearWindow({type: 'create_campaign'}),
|
close: () => ClearWindow({type: 'create_campaign'}),
|
||||||
movable: true
|
movable: true
|
||||||
},
|
|
||||||
create_note: {
|
|
||||||
title: "Create note",
|
|
||||||
component: () => import('~/components/windows/CreateNoteWindow.vue'),
|
|
||||||
close: () => ClearWindow({type: 'create_note'}),
|
|
||||||
movable: true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user