Skip to content

Commit

Permalink
fix: avoid to show empty preview when changing to active editor of no…
Browse files Browse the repository at this point in the history
…n-vue file (#42)

* fix: avoid to show empty preview when changing to active editor of non-vue file

* feat: display current component name in preview
  • Loading branch information
ktsn committed Jun 29, 2018
1 parent 6b07626 commit b1c230b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/message/bus.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as path from 'path'
import { MessageBus } from 'meck'
import { Events, Commands } from './types'
import {
Expand All @@ -19,6 +20,10 @@ import {
import { AssetResolver } from '../asset-resolver'
import { mapValues } from '../utils'

function isInterested(uri: string): boolean {
return path.extname(uri) === '.vue'
}

export function observeServerEvents(
bus: MessageBus<Events, Commands>,
assetResolver: AssetResolver,
Expand Down Expand Up @@ -117,8 +122,10 @@ export function observeServerEvents(
})

bus.on('changeActiveEditor', uri => {
lastActiveUri = uri
bus.emit('changeDocument', uri)
if (isInterested(uri)) {
lastActiveUri = uri
bus.emit('changeDocument', uri)
}
})

bus.on('updateEditor', ({ uri, code }) => {
Expand Down
17 changes: 14 additions & 3 deletions src/view/components/PageMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
</div>

<div v-if="document" class="information-pane" :class="{ open: openPane }">
<p class="information-pane-title">
{{ documentName }}
</p>

<div class="information-pane-scroller">
<div
v-if="selectedPath.length > 0"
Expand Down Expand Up @@ -123,6 +127,7 @@ export default Vue.extend({
...projectMapper.mapGetters({
document: 'currentDocument',
scope: 'currentScope',
documentName: 'currentDocumentName',
renderingDocument: 'currentRenderingDocument',
scopedDocuments: 'scopedDocuments'
}),
Expand Down Expand Up @@ -194,10 +199,16 @@ export default Vue.extend({
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
transform: translateX(100%);
transition: transform 400ms cubic-bezier(0.19, 1, 0.22, 1);
}
&.open {
transform: translateX(0);
}
.information-pane.open {
transform: translateX(0);
}
.information-pane-title {
margin: 0;
padding: 13px 15px 0;
font-size: rem(20);
}
.information-pane-scroller {
Expand Down
6 changes: 6 additions & 0 deletions src/view/store/modules/project/project-getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export class ProjectGetters extends Getters<ProjectState>() {
return state.documents[state.currentUri]
}

get currentDocumentName(): string | undefined {
return this.currentRenderingDocument
? this.currentRenderingDocument.displayName
: undefined
}

get currentScope(): DocumentScope | undefined {
const { state } = this
if (!state.currentUri) {
Expand Down

0 comments on commit b1c230b

Please sign in to comment.