-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathApp.vue
More file actions
67 lines (58 loc) · 1.71 KB
/
App.vue
File metadata and controls
67 lines (58 loc) · 1.71 KB
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
<template>
<div id="MarkdownApp">
<div v-if="isLoading">LOADING</div>
<MarkdownView v-if="isRendering" v-bind:markdown="markdown" v-on:edit="toggle" />
<MarkdownEdit v-if="isEditing" v-bind:markdown="markdown" v-on:save="toggle" />
</div>
</template>
<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';
import MarkdownView from './components/MarkdownView.vue'
import { NamedNode } from 'rdflib'
import { loadMarkdown, saveMarkdown, STATE } from './markdown.service'
import MarkdownEdit from './components/MarkdownEdit.vue'
@Component({
components: {
MarkdownEdit,
MarkdownView
}
})
export default class App extends Vue {
state: STATE = STATE.LOADING
markdown: string = ''
@Prop(NamedNode) subject!: NamedNode
created (): void {
loadMarkdown(this.subject.uri)
.then(responseText => {
this.markdown = responseText
this.state = STATE.RENDERING
})
}
toggle (markdown: string): void {
const wasEditing = this.state === STATE.EDITING
if (wasEditing) {
this.state = STATE.LOADING
saveMarkdown(this.subject.uri, markdown)
.then(() => this.markdown = markdown)
.then(() => this.state = STATE.RENDERING)
return
}
this.state = STATE.EDITING
}
get isEditing (): boolean {
return this.state === STATE.EDITING
}
get isLoading (): boolean {
return this.state === STATE.LOADING
}
get isRendering (): boolean {
return this.state === STATE.RENDERING
}
}
</script>
<style scoped lang="scss">
#MarkdownApp {
border: solid 3px red;
padding: 3px;
}
</style>