Skip to content

Commit 7250ae0

Browse files
authored
#508 apply tiptap editor to problem quetion (#509)
* 에디터 placeholder 추가, 높이지정 style 추가 * 문제 질문하기 tiptap에디터 적용,질문 미리보기에 html적용 * 모달 주석 간단하게 수정
1 parent 21d8fc4 commit 7250ae0

2 files changed

Lines changed: 54 additions & 10 deletions

File tree

frontend/src/pages/oj/components/TiptapEditor.vue

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template>
22
<div class="editor-wrapper" :class="{ 'is-focused': editor && editor.focused, 'is-readonly': !editable }">
3+
<!-- 에티터 메뉴바 -->
34
<div class="editor-menubar" v-if="editor && editable">
45
<!-- 진하게 -->
56
<div class="menubar__button" :class="{ 'is-active': editor.isActive.bold() }"
@@ -78,8 +79,9 @@
7879
<Icon type="forward" size="20"></Icon>
7980
</div>
8081
</div>
81-
82-
<div class="editor-content-box" :class="{ 'readonly-content': !editable }">
82+
<!-- 에디터 글 쓰는 곳 (최소 높이 지정 가능) -->
83+
<div class="editor-content-box" :class="{ 'readonly-content': !editable }" :style="{ minHeight: minHeight }"
84+
@click="focusEditor">
8385
<editor-content class="editor__content" :editor="editor" />
8486
</div>
8587
</div>
@@ -102,6 +104,7 @@ import {
102104
Strike,
103105
Underline,
104106
History,
107+
Placeholder,
105108
} from 'tiptap-extensions';
106109
107110
// 언어별 하이라이팅 라이브러리
@@ -158,6 +161,14 @@ export default {
158161
type: Boolean,
159162
default: true,
160163
},
164+
minHeight: {
165+
type: String,
166+
default: '400px',
167+
},
168+
placeholder: {
169+
type: String,
170+
default: '',
171+
},
161172
},
162173
data() {
163174
return {
@@ -209,13 +220,24 @@ export default {
209220
javascript, python, cpp, java, bash, go
210221
},
211222
}),
223+
new Placeholder({
224+
emptyNodeClass: 'is-empty',
225+
emptyNodeText: this.placeholder,
226+
showOnlyWhenEditable: true,
227+
}),
212228
],
213229
content: this.value,
214230
onUpdate: ({ getHTML }) => {
215231
this.$emit('input', getHTML());
216232
},
217233
});
218234
},
235+
// 에디터 어느 곳이나 마우스 클릭하면 글 쓰기 모드로 전환
236+
focusEditor() {
237+
if (this.editor && !this.editor.focused && this.editable) {
238+
this.editor.focus()
239+
}
240+
},
219241
},
220242
}
221243
</script>
@@ -316,13 +338,12 @@ export default {
316338
317339
.editor-content-box {
318340
background: white;
319-
min-height: 400px;
320341
cursor: text;
321342
padding: 20px;
322343
323344
&.readonly-content {
324345
padding: 0;
325-
min-height: auto;
346+
min-height: auto !important;
326347
}
327348
}
328349
@@ -331,10 +352,19 @@ export default {
331352
outline: none;
332353
}
333354
334-
/* ProseMirror Content Styles */
355+
// placeholder 스타일
356+
/deep/ .ProseMirror p.is-empty:first-child::before {
357+
content: attr(data-empty-text);
358+
float: left;
359+
color: #aaa;
360+
pointer-events: none;
361+
height: 0;
362+
}
363+
335364
/deep/ .ProseMirror {
336365
outline: none;
337-
min-height: 360px;
366+
height: 100%;
367+
min-height: inherit;
338368
font-size: 16px;
339369
line-height: 1.7;
340370
color: #2c3e50;

frontend/src/pages/oj/views/problem/problemSolving/problemSolvingComponent/ProblemCommunity.vue

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
</div>
6666
<h4 class="post-title">{{ post.title }}</h4>
6767
</div>
68-
<p v-if="post.content_preview" class="post-preview">{{ post.content_preview }}</p>
68+
<div v-if="post.content_preview" class="post-preview" v-html="post.content_preview"></div>
6969
<div class="post-footer">
7070
<div class="author-info">
7171
<img class="avatar" :src="post.author_avatar || defaultAvatar" alt="avatar" />
@@ -85,7 +85,7 @@
8585
</div>
8686
</div>
8787

88-
<Modal v-model="showCreateModal" :footer-hide="true" :closable="true" :mask-closable="false" width="650"
88+
<Modal v-model="showCreateModal" :footer-hide="true" :closable="true" :mask-closable="false" width="800"
8989
class-name="create-question-modal">
9090
<div class="modal-header">
9191
<h2 class="modal-title">
@@ -113,7 +113,7 @@
113113
<div class="input-label">
114114
{{ $t("m.Problem_Community_Modal_Content_Label") }}
115115
</div>
116-
<Input v-model="newPost.content" type="textarea" :autosize="{ minRows: 8, maxRows: 15 }"
116+
<TiptapEditor v-model="newPost.content" minHeight="300px" :editable="true"
117117
:placeholder="$t('m.Problem_Community_Modal_Content_Placeholder')" />
118118
</FormItem>
119119
</Form>
@@ -137,9 +137,13 @@
137137
import api from "@oj/api"
138138
import { DEFAULT_AVATAR, QUESTION_STATUS } from "@/utils/constants"
139139
import { mapGetters } from "vuex"
140+
import TiptapEditor from "../../../../components/TiptapEditor.vue"
140141
141142
export default {
142143
name: "ProblemCommunity",
144+
components: {
145+
TiptapEditor
146+
},
143147
props: {
144148
problemID: {
145149
type: String,
@@ -772,8 +776,18 @@ export default {
772776
}
773777
}
774778
775-
// Modal styles
779+
// top, bottom 모두 padding 주어 화면 중앙에 모달이 위치하도록 설정
776780
/deep/ .create-question-modal {
781+
display: flex;
782+
align-items: center;
783+
justify-content: center;
784+
padding-top: 50px;
785+
padding-bottom: 50px;
786+
787+
.ivu-modal {
788+
top: 0;
789+
}
790+
777791
.ivu-modal-content {
778792
border-radius: 16px;
779793
overflow: hidden;

0 commit comments

Comments
 (0)