This repository has been archived by the owner on May 4, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
EntryEditorView.vue
133 lines (110 loc) 路 4.11 KB
/
EntryEditorView.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<template>
<div class="h-screen bg-white flex flex-col">
<div class="p-4 border-b shadow text-right">
<button @click="store" @keyup.meta.31="store" class="bg-green hover:bg-green-dark inline-block text-white no-underline font-bold py-2 px-4 rounded cursor-pointer">Save</button>
<delete-entry-button :entryId="entryId" :journalId="journalId"></delete-entry-button>
</div>
<div class="p-8 flex-grow overflow-scroll">
<form @submit.prevent="store">
<div class="mb-4">
<input
type="text"
v-model="title"
placeholder="This is the title of your entry"
class="shadow appearance-none inline-block border rounded py-2 px-3 text-grey-darker w-full"
>
</div>
<div class="form-group">
<textarea
:value="content"
rows="10"
placeholder="The content of your entry. **Markdown** is *supported*!"
class="shadow appearance-none inline-block border rounded py-2 px-3 text-grey-darker w-full"
@focus="updateSizeOfTextarea"
@input="update"
></textarea>
</div>
{{ entry.attributes.id }}
<files-list :files="files" :entryId="entryId"></files-list>
</form>
</div>
<div class="p-4 border-t">
<files-bag :files="files" :entryId="entryId"></files-bag>
</div>
</div>
</template>
<script>
import autosize from 'autosize';
import Crypto from './../../classes/Crypto.js';
import FilesBag from './../../components/Util/FilesBag.vue';
import FilesList from './../../components/Util/FilesList.vue';
import DeleteEntryButton from './../../components/Entry/DeleteEntryButton.vue';
export default {
props: ['journalId', 'entryId'],
data() {
return {
title: '',
content: ''
}
},
components: {
FilesBag,
FilesList,
DeleteEntryButton
},
watch: {
'$route': 'fetchData'
},
created() {
this.fetchData();
this.$on('receivedEntry', function(entry) {
this.updateSizeOfTextarea();
this.title = new Crypto(this.$store.state.encryption_password).decrypt(entry.attributes.title);
this.content = new Crypto(this.$store.state.encryption_password).decrypt(entry.attributes.content);
});
},
methods: {
fetchData () {
this.$store.dispatch('getEntry', this.entryId);
this.$store.dispatch('getMedia', this.entryId);
},
updateSizeOfTextarea() {
autosize(document.querySelector('textarea'));
},
update (e) {
this.updateSizeOfTextarea();
this.content = e.target.value;
},
store () {
this.$store.dispatch('updateEntry', {
entryId: this.entry.id,
title: new Crypto(this.$store.state.encryption_password).encrypt(this.title),
content: new Crypto(this.$store.state.encryption_password).encrypt(this.content)
}).then(() => {
this.$store.dispatch('getEntry', this.entryId);
this.$store.dispatch('getEntries', this.journalId);
this.$router.push({
name: 'entries.show',
params: {
journalId: this.journalId,
entryId: this.entryId
}
});
});
}
},
computed: {
files() {
return this.$store.state.files;
},
entry() {
// Emit a custom event to trigger decrypt entry content
// and write title and content to local properties
if (this.$store.state.entry != null) {
this.$emit('receivedEntry', this.$store.state.entry);
}
return this.$store.state.entry;
}
}
}
</script>