Skip to content

Commit

Permalink
Allow opening files outside of the file system in viewer
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Aug 24, 2022
1 parent c77ecc0 commit 33a17b9
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/components/ViewerComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,25 @@
-->

<template>
<Editor :file-id="fileid"
<Editor v-if="false"
:file-id="fileid"
:relative-path="filename"
:active="active"
:autofocus="autofocus"
:share-token="shareToken"
:mime="mime" />
<Component :is="readerComponent" v-else :content="content" />
</template>

<script>
import axios from '@nextcloud/axios'
import PlainTextReader from './PlainTextReader.vue'
import RichTextReader from './RichTextReader.vue'
export default {
name: 'ViewerComponent',
components: {
RichTextReader,
PlainTextReader,
Editor: () => import(/* webpackChunkName: "editor" */'./Editor.vue'),
},
props: {
Expand Down Expand Up @@ -60,13 +67,33 @@ export default {
type: String,
default: null,
},
source: {
type: String,
default: undefined,
},
},
data() {
return {
content: '',
}
},
beforeMount() {
// FIXME Dirty fix to avoid recreating the component on stable16
if (typeof this.$parent.$parent !== 'undefined' && this.$parent.$parent.onResize) {
window.removeEventListener('resize', this.$parent.$parent.onResize)
}
},
mounted() {
axios.get(this.source).then(({ data }) => {
this.content = data
this.$emit('update:loaded', true)
})
},
computed: {
readerComponent() {
return this.mime === 'text/markdown' ? RichTextReader : PlainTextReader
},
},
}
</script>
<style lang="scss">
Expand Down

0 comments on commit 33a17b9

Please sign in to comment.