1111 </button >
1212
1313 <div class =" editorWrapper" >
14- <textarea class =" markdown" v-model =" markdown" ></textarea >
14+ <div class =" memoListWrapper" >
15+ <!-- :data-selected (v-bind:deta-selected) と明示的に記述して内容に応じてスタイルを当てる -->
16+ <div class =" memoList" v-for =" (memo, index) in memos" @click =" selectMemo(index)" :data-selected =" index == selectedIndex" >
17+ <p class =" memoTitle" >
18+ {{ displayTitle(memo.markdown) }}
19+ </p >
20+ </div >
21+ <button class =" addMemoBtn" @click =" addMemo" >
22+ メモの追加
23+ </button >
24+ </div >
25+ <textarea class =" markdown" v-model =" memos[selectedIndex].markdown" ></textarea >
1526 <div class =" preview" v-html =" preview()" ></div >
1627 </div >
17-
1828 </div >
1929</template >
2030
@@ -25,16 +35,34 @@ export default {
2535 name: " editor" ,
2636 props: [" user" ],
2737 data () {
38+ // 配列にすることで複数のメモを格納できるようにする
39+ // Lodash などを用いて検索機能やソート機能を実装してみるのもよい
2840 return {
29- markdown: " "
41+ memos: [
42+ {
43+ markdown: " "
44+ }
45+ ],
46+ selectedIndex: 0
3047 }
3148 },
3249 methods: {
3350 logout : function () {
3451 firebase .auth ().signOut ()
3552 },
3653 preview : function () {
37- return marked (this .markdown )
54+ return marked (this .memos [this .selectedIndex ].markdown )
55+ },
56+ addMemo : function () {
57+ this .memos .push ({
58+ markdown: " 無題のメモ"
59+ })
60+ },
61+ selectMemo : function (index ) {
62+ this .selectedIndex = index
63+ },
64+ displayTitle : function (text ) {
65+ return text .split (/ \n / )[0 ]
3866 }
3967 }
4068}
@@ -45,13 +73,42 @@ export default {
4573 display : flex ;
4674}
4775
76+ .memoListWrapper {
77+ width : 20% ;
78+ border-top : 1px solid #000 ;
79+ }
80+
81+ .memoList {
82+ padding : 10px ;
83+ box-sizing : border-box ;
84+ text-align : left ;
85+ border-bottom : 1px solid #000 ;
86+ & :nth-child (even ) {
87+ background-color : #ccc ;
88+ }
89+ & [data-selected = " true" ] {
90+ background-color : #ccf ;
91+ }
92+ }
93+
94+ .memoTitle {
95+ height : 1.5em ;
96+ margin : 0 ;
97+ white-space : nowrap ;
98+ overflow : hidden ;
99+ }
100+
101+ .addMemoBtn {
102+ margin-top : 20px ;
103+ }
104+
48105.markdown {
49- width : 50 % ;
106+ width : 40 % ;
50107 height : 500px ;
51108}
52109
53110.preview {
54- width : 50 % ;
111+ width : 40 % ;
55112 text-align : left ;
56113}
57114 </style >
0 commit comments