Skip to content
This repository was archived by the owner on Sep 13, 2023. It is now read-only.

Commit c332781

Browse files
committed
Add Tab functionality in UpdateNoteModal
1 parent f31e780 commit c332781

File tree

3 files changed

+80
-41
lines changed

3 files changed

+80
-41
lines changed

src/renderer/components/modals/update-note-modal/UpdateNoteModal.html

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,42 @@
55
<h2 class="text-red" v-if="displayDupError">Oh sorry, you can't have duplicated name in your note files...</h2>
66
</header>
77

8+
<Tab
9+
ref="tab"
10+
v-if="files.length"
11+
:dataArr="files"
12+
v-slot:name="{ item }"
13+
@onFileSelected="selectedFile = $event"
14+
>
15+
{{ item.name }}
16+
</Tab>
17+
18+
<!-- Selected file -->
19+
<div v-if="selectedFile !== null" :class="{ 'c-selected-file': true }">
20+
<b-field horizontal label="Name" grouped>
21+
<b-input style="width: 186px" type="text" v-model="selectedFile.name" placeholder="Your file name">
22+
</b-input>
23+
<p class="control is-pulled-right">
24+
<button class="button is-danger" @click="deleteFile(selectedFile)">
25+
<b-icon icon="trash"></b-icon>
26+
</button>
27+
</p>
28+
</b-field>
29+
30+
<b-field horizontal label="Language">
31+
<b-select placeholder="Select a language" v-model="selectedFile.language">
32+
<option v-for="language in languages" :value="language.name">
33+
{{ language.name | capitalize }}
34+
</option>
35+
</b-select>
36+
</b-field>
37+
38+
<b-field horizontal label="Content">
39+
<editor v-model="selectedFile.content" :lang="selectedFile.language" theme="monokai" width="100%" height="260">
40+
</editor>
41+
</b-field>
42+
</div>
43+
844
<section class="modal-card-body">
945
<b-field v-if="!gistsSelected" horizontal label="Name">
1046
<b-input
@@ -32,48 +68,30 @@ <h2 class="text-red" v-if="displayDupError">Oh sorry, you can't have duplicated
3268
</b-taginput>
3369
</b-field>
3470

35-
<div class="note-file" v-for="file in files">
36-
<b-field horizontal label="Name" grouped>
37-
<b-input
38-
style="width: 186px"
39-
type="text"
40-
v-model="file.name"
41-
placeholder="Your file name">
42-
</b-input>
43-
<p class="control is-pulled-right" v-if="files.length > 1">
44-
<button class="button is-danger" @click="deleteFile(file)">
45-
<b-icon icon="trash"></b-icon>
46-
</button>
47-
</p>
48-
</b-field>
4971

50-
<b-field horizontal label="Language">
51-
<b-select placeholder="Select a language" v-model="file.language">
52-
<option
53-
v-for="language in languages"
54-
:value="language.name">
55-
{{ language.name | capitalize }}
56-
</option>
57-
</b-select>
58-
</b-field>
72+
<b-field horizontal label="Name" grouped>
73+
<b-input style="width: 186px" type="text" v-model="baseFile.name" placeholder="Your file name">
74+
</b-input>
75+
</b-field>
5976

60-
<b-field horizontal label="Content">
61-
<editor v-model="file.content"
62-
:lang="file.language"
63-
theme="monokai"
64-
width="100%"
65-
height="260"
66-
></editor>
67-
</b-field>
68-
</div>
77+
<b-field horizontal label="Language">
78+
<b-select placeholder="Select a language" v-model="baseFile.language">
79+
<option v-for="language in languages" :value="language.name">
80+
{{ language.name | capitalize }}
81+
</option>
82+
</b-select>
83+
</b-field>
84+
85+
<b-field horizontal label="Content">
86+
<editor v-model="baseFile.content" :lang="baseFile.language" theme="monokai" width="100%" height="260"></editor>
87+
</b-field>
6988

7089
<div class="text-center">
71-
<button class="button" type="button" @click="addFile()" v-if="files.length < 5">
90+
<button class="button" type="button" @click="addFile()">
7291
<b-icon id="plus" icon="plus"></b-icon>
7392
Add a file
7493
</button>
7594
</div>
76-
7795
</section>
7896

7997
<footer class="modal-card-foot">

src/renderer/components/modals/update-note-modal/UpdateNoteModal.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@
1515
padding: 12px;
1616
margin-bottom: 10px;
1717
}
18+
19+
.c-selected-file {
20+
background-color: $light;
21+
border-top: 1px solid #ccc;
22+
padding: 1rem;
23+
max-height: 20rem;
24+
}

src/renderer/components/modals/update-note-modal/UpdateNoteModal.vue

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import { mapGetters, mapActions } from 'vuex';
33
import editor from '@/components/editor/Editor';
44
import languages from '@/assets/data/languages.json';
55
import converter from '@/converter';
6+
import Tab from '../../tab/Tab';
7+
8+
import { createId } from '../../../utils';
69
710
export default {
811
template: require('./UpdateNoteModal.html'),
912
name: 'cn-update-note-modal',
10-
components: { editor },
13+
components: { editor, Tab },
1114
props: {
1215
note: Object,
1316
},
@@ -25,6 +28,12 @@ export default {
2528
gistFiles: [],
2629
languages,
2730
displayDupError: false,
31+
selectedFile: null,
32+
baseFile: {
33+
name: '',
34+
language: 'text',
35+
content: '',
36+
},
2837
};
2938
},
3039
mounted() {
@@ -38,10 +47,10 @@ export default {
3847
this.noteUpdated = { ...this.note };
3948
this.noteUpdated.files = {};
4049
Object.keys(this.note.files).forEach((key, index) => {
41-
this.files.push({ ...this.note.files[key], id: index });
50+
this.files.push({ ...this.note.files[key], id: createId() });
4251
this.gistFiles.push({
4352
...this.note.files[key],
44-
id: index,
53+
id: createId(),
4554
deleted: false,
4655
});
4756
});
@@ -94,12 +103,15 @@ export default {
94103
},
95104
addFile() {
96105
this.files.push({
97-
name: '',
98-
language: 'text',
99-
content: '',
106+
id: createId(),
107+
...this.baseFile,
100108
deleted: false,
101109
added: true,
102110
});
111+
112+
Object.keys(this.baseFile).forEach(
113+
k => this.baseFile[k] = k !== 'language' ? '': this.languages[0].name
114+
);
103115
},
104116
deleteFile(file) {
105117
if (this.gistsSelected) {
@@ -111,6 +123,8 @@ export default {
111123
}
112124
113125
this.files = this.files.filter(f => f !== file);
126+
this.$refs.tab.recomputeSlidesLen();
127+
this.selectedFile = null;
114128
},
115129
containsDupFiles() {
116130
const map = new Map();
@@ -134,7 +148,7 @@ export default {
134148
computed: {
135149
...mapGetters(['gistsSelected']),
136150
isDisabled() {
137-
return this.files.some(file => !/\S/.test(file.content));
151+
return !this.files.length || this.files.some(file => !/\S/.test(file.content));
138152
},
139153
},
140154
};

0 commit comments

Comments
 (0)