-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
338ac72
commit 4c02940
Showing
9 changed files
with
254 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<script setup lang="ts"> | ||
import ObsidianSetting from "../obsidian/ObsidianSetting.vue"; | ||
import ObsidianTextInput from "../obsidian/ObsidianTextInput.vue"; | ||
import ObsidianButton from "../obsidian/ObsidianButton.vue"; | ||
import { useForm } from "vee-validate"; | ||
import { toTypedSchema } from "@vee-validate/valibot"; | ||
import * as v from "valibot"; | ||
import FormErrors from "../FormErrors.vue"; | ||
import { pluginSettings$ } from "@/stores/settings.store"; | ||
const emit = defineEmits<{ | ||
(event: "create", name: string): void; | ||
(event: "close"): void; | ||
}>(); | ||
function isNameNotUnique(value: string) { | ||
return !(value in pluginSettings$.value.shelves); | ||
} | ||
const { defineField, errorBag, handleSubmit } = useForm({ | ||
initialValues: { | ||
name: "", | ||
}, | ||
validationSchema: toTypedSchema( | ||
v.object({ | ||
name: v.pipe( | ||
v.string(), | ||
v.nonEmpty("Shelf name is required"), | ||
v.check(isNameNotUnique, "Shelf name should be unique"), | ||
), | ||
}), | ||
), | ||
}); | ||
const [name, nameAttrs] = defineField("name"); | ||
const onSubmit = handleSubmit((values) => { | ||
emit("create", values.name); | ||
emit("close"); | ||
}); | ||
</script> | ||
|
||
<template> | ||
<form @submit.prevent="onSubmit"> | ||
<ObsidianSetting name="Journal name"> | ||
<template #description> | ||
<FormErrors :errors="errorBag.name" /> | ||
</template> | ||
<ObsidianTextInput v-model="name" placeholder="ex. Work" v-bind="nameAttrs" /> | ||
</ObsidianSetting> | ||
<ObsidianSetting> | ||
<ObsidianButton @click="emit('close')">Close</ObsidianButton> | ||
<ObsidianButton cta type="submit" @click="onSubmit">Add</ObsidianButton> | ||
</ObsidianSetting> | ||
</form> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<script setup lang="ts"> | ||
import { computed, ref } from "vue"; | ||
import ObsidianSetting from "../obsidian/ObsidianSetting.vue"; | ||
import ObsidianDropdown from "../obsidian/ObsidianDropdown.vue"; | ||
import ObsidianButton from "../obsidian/ObsidianButton.vue"; | ||
import { pluginSettings$ } from "@/stores/settings.store"; | ||
const { shelfName } = defineProps<{ | ||
shelfName: string; | ||
}>(); | ||
const emit = defineEmits<{ | ||
(event: "close"): void; | ||
(event: "remove", destination: string): void; | ||
}>(); | ||
const destinationShelf = ref(""); | ||
const otherShelves = computed(() => { | ||
return Object.values(pluginSettings$.value.shelves).filter((shelf) => shelf.name !== shelfName); | ||
}); | ||
function confirm() { | ||
emit("remove", destinationShelf.value); | ||
emit("close"); | ||
} | ||
</script> | ||
|
||
<template> | ||
<ObsidianSetting v-if="otherShelves.length > 0" name="Move journals to"> | ||
<ObsidianDropdown v-model="destinationShelf"> | ||
<option value="">None</option> | ||
<option v-for="shelf in otherShelves" :key="shelf.name" :value="shelf.name">{{ shelf.name }}</option> | ||
</ObsidianDropdown> | ||
</ObsidianSetting> | ||
<p v-else>Journals will be moved out</p> | ||
<ObsidianSetting> | ||
<ObsidianButton @click="$emit('close')">Cancel</ObsidianButton> | ||
<ObsidianButton cta @click="confirm">Remove</ObsidianButton> | ||
</ObsidianSetting> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<script setup lang="ts"> | ||
import ObsidianSetting from "@/components/obsidian/ObsidianSetting.vue"; | ||
import ObsidianIconButton from "@/components/obsidian/ObsidianIconButton.vue"; | ||
import { VueModal } from "@/components/modals/vue-modal"; | ||
import CreateShelf from "@/components/modals/CreateShelf.modal.vue"; | ||
import RemoveShelf from "@/components/modals/RemoveShelf.modal.vue"; | ||
import { plugin$ } from "@/stores/obsidian.store"; | ||
import { pluginSettings$ } from "@/stores/settings.store"; | ||
import { computed } from "vue"; | ||
defineEmits<(event: "organize", shelfName: string) => void>(); | ||
const shelvesList = computed(() => | ||
Object.values(pluginSettings$.value.shelves).toSorted((a, b) => a.name.localeCompare(b.name)), | ||
); | ||
const journalsWithoutShelf = computed(() => { | ||
const journals = Object.values(pluginSettings$.value.journals); | ||
return journals.filter((journal) => journal.shelves.length === 0); | ||
}); | ||
function createShelf(): void { | ||
new VueModal("Add Journal Shelf", CreateShelf, { | ||
onCreate(name: string) { | ||
plugin$.value.createShelf(name); | ||
}, | ||
}).open(); | ||
} | ||
function removeShelf(shelfName: string): void { | ||
const shelf = pluginSettings$.value.shelves[shelfName]; | ||
if (!shelf) return; | ||
new VueModal(`Remove ${shelf.name} shelf`, RemoveShelf, { | ||
shelfName, | ||
onRemove(destinationShelf: string) { | ||
plugin$.value.removeShelf(shelfName, destinationShelf); | ||
}, | ||
}).open(); | ||
} | ||
</script> | ||
|
||
<template> | ||
<ObsidianSetting name="Journal shelves" heading> | ||
<ObsidianIconButton :icon="'plus'" cta tooltip="Create new shelf" @click="createShelf" /> | ||
</ObsidianSetting> | ||
<p v-if="shelvesList.length === 0">No shelves configured yet.</p> | ||
<template v-else> | ||
<ObsidianSetting v-for="shelf of shelvesList" :key="shelf.name"> | ||
<template #name> | ||
<b> | ||
{{ shelf.name }} </b | ||
><br /> | ||
{{ shelf.journals.length }} journals | ||
</template> | ||
<ObsidianIconButton icon="library" :tooltip="'Organize ' + shelf.name" @click="$emit('organize', shelf.name)" /> | ||
<ObsidianIconButton icon="trash-2" :tooltip="'Delete ' + shelf.name" @click="removeShelf(shelf.name)" /> | ||
</ObsidianSetting> | ||
</template> | ||
<template v-if="journalsWithoutShelf.length > 0"> | ||
<ObsidianSetting name="Journals without shelf" heading /> | ||
</template> | ||
</template> | ||
|
||
<style scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<script setup lang="ts"> | ||
import ObsidianSetting from "@/components/obsidian/ObsidianSetting.vue"; | ||
import JournalSettingsList from "./JournalSettingsList.vue"; | ||
import ObsidianIconButton from "@/components/obsidian/ObsidianIconButton.vue"; | ||
import { VueModal } from "@/components/modals/vue-modal"; | ||
import CreateJournal from "@/components/modals/CreateJournal.modal.vue"; | ||
import RemoveJournal from "@/components/modals/RemoveJournal.modal.vue"; | ||
import { plugin$ } from "@/stores/obsidian.store"; | ||
import type { JournalSettings, NotesProcessing } from "@/types/settings.types"; | ||
import { journals$ } from "@/stores/settings.store"; | ||
const emit = defineEmits<(event: "edit", name: string) => void>(); | ||
function create(): void { | ||
new VueModal("Add Journal", CreateJournal, { | ||
onCreate(name: string, writing: JournalSettings["write"]) { | ||
plugin$.value.createJournal(name, writing); | ||
}, | ||
}).open(); | ||
} | ||
function edit(name: string): void { | ||
emit("edit", name); | ||
} | ||
function remove(name: string): void { | ||
const journal = journals$.value[name]; | ||
if (!journal) return; | ||
new VueModal(`Remove ${journal.name} journal`, RemoveJournal, { | ||
onRemove(_noteProcessing: NotesProcessing) { | ||
// TODO Process notes on remove | ||
plugin$.value.removeJournal(name); | ||
}, | ||
}).open(); | ||
} | ||
</script> | ||
|
||
<template> | ||
<ObsidianSetting name="Journals" heading> | ||
<ObsidianIconButton :icon="'plus'" cta tooltip="Create new journal" @click="create" /> | ||
</ObsidianSetting> | ||
|
||
<JournalSettingsList @edit="edit" @remove="remove" /> | ||
</template> | ||
|
||
<style scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters