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

Commit f895994

Browse files
authored
refactor(notes): Multi snippets in one note (#15)
1 parent d21898c commit f895994

34 files changed

+763
-565
lines changed

src/renderer/App.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<template>
22
<div id="app">
3-
<cb-navbar></cb-navbar>
3+
<cn-navbar></cn-navbar>
44
<div id="content">
55
<div class="columns">
66
<div class="column is-3">
7-
<cb-sidebar></cb-sidebar>
7+
<cn-sidebar></cn-sidebar>
88
</div>
99
<div class="column is-9">
1010
<router-view></router-view>
@@ -19,10 +19,10 @@ import Navbar from './Navbar';
1919
import Sidebar from './Sidebar';
2020
2121
export default {
22-
name: 'cb-app',
22+
name: 'cn-app',
2323
components: {
24-
'cb-navbar': Navbar,
25-
'cb-sidebar': Sidebar,
24+
'cn-navbar': Navbar,
25+
'cn-sidebar': Sidebar,
2626
},
2727
};
2828
</script>

src/renderer/Navbar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import { remote } from 'electron';
3939
4040
export default {
41-
name: 'cb-navbar',
41+
name: 'cn-navbar',
4242
data() {
4343
return {
4444
appVersion: remote.app.getVersion(),

src/renderer/Sidebar.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</p>
66
<ul class="menu-list">
77
<li>
8-
<a :class="{'is-active': languageSelected === 'all'}" @click="selectLanguage('all')">All <b-tag class="is-pulled-right" type="is-dark">{{snippets.length}}</b-tag></a>
8+
<a :class="{'is-active': languageSelected === 'all'}" @click="selectLanguage('all')">All <b-tag class="is-pulled-right" type="is-dark">{{totalFiles}}</b-tag></a>
99
</li>
1010
<li v-for="(list, value) in Array.from(languages)">
1111
<a :class="{'is-active': languageSelected === list[0]}" @click="selectLanguage(list[0])">{{list[0] | capitalize}} <b-tag class="is-pulled-right" type="is-dark">{{list[1]}}</b-tag></a>
@@ -18,7 +18,7 @@
1818
import Vuex from 'vuex';
1919
2020
export default {
21-
name: 'cb-sidebar',
21+
name: 'cn-sidebar',
2222
data() {
2323
return {};
2424
},
@@ -28,7 +28,7 @@ export default {
2828
},
2929
},
3030
computed: {
31-
...Vuex.mapGetters(['languages', 'snippets', 'languageSelected']),
31+
...Vuex.mapGetters(['languages', 'notes', 'languageSelected', 'totalFiles']),
3232
},
3333
};
3434
</script>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<form action="">
2+
<div class="modal-card">
3+
<header class="modal-card-head">
4+
<p class="modal-card-title">Create note</p>
5+
<h2 class="text-red" v-if="displayDupError">Oh sorry, you can't have duplicated name in your note files...</h2>
6+
</header>
7+
8+
<section class="modal-card-body">
9+
<b-field horizontal label="Name">
10+
<b-input
11+
type="text"
12+
ref="noteName"
13+
v-model="note.name"
14+
placeholder="Your note name"
15+
required>
16+
</b-input>
17+
</b-field>
18+
19+
<b-field horizontal label="Description">
20+
<b-input
21+
type="text"
22+
v-model="note.description"
23+
placeholder="Your note description">
24+
</b-input>
25+
</b-field>
26+
27+
<div class="note-file" v-for="file in files">
28+
<b-field horizontal label="Filename" grouped>
29+
<b-input
30+
style="width: 186px"
31+
type="text"
32+
v-model="file.name"
33+
placeholder="Your file name">
34+
</b-input>
35+
<p class="control is-pulled-right" v-if="files.length > 1">
36+
<button class="button is-danger" @click="deleteFile(file)"><b-icon icon="trash"></b-icon></button>
37+
</p>
38+
</b-field>
39+
40+
<b-field horizontal label="Language">
41+
<b-select placeholder="Select a language" v-model="file.language">
42+
<option
43+
v-for="language in languages"
44+
:value="language.name">
45+
{{ language.name | capitalize }}
46+
</option>
47+
</b-select>
48+
</b-field>
49+
50+
<b-field horizontal label="Content">
51+
<editor v-model="file.content"
52+
:lang="file.language"
53+
theme="monokai"
54+
width="100%"
55+
height="260"
56+
></editor>
57+
</b-field>
58+
</div>
59+
<button class="button" type="button" @click="addFile()" v-if="files.length < 5"><b-icon id="plus" icon="plus"></b-icon> Add a file</button>
60+
</section>
61+
62+
<footer class="modal-card-foot">
63+
<button class="button" type="button" @click="$parent.close()">Cancel</button>
64+
<button class="button is-primary" type="button" :disabled="isDisabled" @click="createNote()">Create</button>
65+
</footer>
66+
</div>
67+
</form>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.modal-card {
2+
width: 700px;
3+
}
4+
5+
.help {
6+
display: none !important;
7+
}
8+
9+
#plus {
10+
margin-right: 4px;
11+
}
12+
13+
.note-file {
14+
background-color: $light;
15+
padding: 12px;
16+
margin-bottom: 10px;
17+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<template src="./CreateNoteModal.html">
2+
</template>
3+
4+
<script>
5+
import editor from '../../editor/Editor';
6+
import languages from '../../../assets/data/languages.json';
7+
import converter from '../../../converter';
8+
9+
export default {
10+
name: 'cn-create-note-modal',
11+
components: {
12+
editor,
13+
},
14+
data() {
15+
return {
16+
note: {
17+
name: '',
18+
description: '',
19+
files: {},
20+
updatedAt: null,
21+
createdAt: null
22+
},
23+
files: [{
24+
name: '',
25+
language: 'text',
26+
content: ''
27+
}],
28+
languages,
29+
displayDupError: false
30+
};
31+
},
32+
mounted() {
33+
this.$refs.noteName.focus();
34+
},
35+
methods: {
36+
createNote() {
37+
if (!this.containsDupFiles()) {
38+
this.files.forEach(file => {
39+
this.note.files[`${file.name}-${converter.languageToExtension(file.language)}`] = file;
40+
});
41+
42+
this.note.createdAt = new Date();
43+
this.note.updatedAt = new Date();
44+
45+
this.$store.dispatch('addNote', this.note).then(() => {
46+
this.$parent.close();
47+
});
48+
}
49+
else {
50+
this.displayDupError = true;
51+
}
52+
},
53+
addFile() {
54+
this.files.push({
55+
name: '',
56+
language: 'text',
57+
content: ''
58+
});
59+
},
60+
deleteFile(file) {
61+
this.files = this.files.filter(f => f !== file);
62+
},
63+
containsDupFiles() {
64+
const map = new Map();
65+
let dupFiles = false;
66+
67+
this.files.forEach(file => {
68+
const key = `${file.name}.${converter.languageToExtension(file.language)}`;
69+
70+
if (map.has(key)) {
71+
dupFiles = true;
72+
}
73+
map.set(key, 1);
74+
});
75+
76+
return dupFiles;
77+
}
78+
},
79+
computed: {
80+
isDisabled() {
81+
return (
82+
!/\S/.test(this.note.name) ||
83+
this.files.some(file => !/\S/.test(file.name) || !/\S/.test(file.language) || !/\S/.test(file.content))
84+
);
85+
},
86+
},
87+
};
88+
</script>
89+
90+
<style src="./CreateNoteModal.scss" lang="scss">
91+
</style>

src/renderer/components/modals/create-snippet-modal/CreateSnippetModal.html

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/renderer/components/modals/create-snippet-modal/CreateSnippetModal.scss

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/renderer/components/modals/create-snippet-modal/CreateSnippetModal.vue

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)