Skip to content

Commit 6e9bfee

Browse files
authored
#573 커뮤니티 게시글 '목록' 버튼 추가를 통한 탐색 편의성 개선 (#575)
* 커뮤니티 게시글 '목록' 버튼 추가를 통한 탐색 편의성 개선 * 커뮤니티 게시글 '목록' 버튼 및 네비게이션 상태 유지 * 목록 버튼 위치 수정, 상수 재정의 * dead code 삭제
1 parent 49a29d9 commit 6e9bfee

3 files changed

Lines changed: 89 additions & 2 deletions

File tree

frontend/src/i18n/oj/en-US.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ export const m = {
548548
Community_Content_Placeholder: "내용을 입력해주세요.",
549549
Community_Post_Edit: "수정",
550550
Community_Post_Delete: "삭제",
551+
Community_List: "목록",
551552
Community_Post_Save: "저장",
552553
Community_Post_Cancel: "취소",
553554
Community_Post_Edit_Success: "게시글이 수정되었습니다.",

frontend/src/pages/oj/views/community/Community.vue

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ export default {
280280
return this.$t("m.Community")
281281
},
282282
},
283+
created() {
284+
this.restoreState() // 복구 로직 실행
285+
},
286+
beforeRouteEnter(to, from, next) {
287+
next()
288+
},
283289
methods: {
284290
/**
285291
* 게시글이 3일 이내에 작성되었는지 확인
@@ -369,8 +375,25 @@ export default {
369375
this.query.page = 1
370376
this.fetchPosts()
371377
},
378+
restoreState() {
379+
const savedJSON = sessionStorage.getItem("communityState")
380+
if (!savedJSON) return false
381+
382+
const savedData = JSON.parse(savedJSON)
383+
384+
if (savedData.routeName === this.$route.name) {
385+
this.query = savedData.query
386+
this.fetchPosts()
387+
return true
388+
}
389+
return false
390+
},
372391
// mount시, 쿼리통해 라우팅
373392
initRoute() {
393+
if (this.restoreState()) {
394+
return
395+
}
396+
374397
this.query.post_type = "ALL"
375398
this.query.question_status = "ALL"
376399
this.query.sort_type = "NEWEST"
@@ -384,6 +407,18 @@ export default {
384407
this.fetchPosts()
385408
},
386409
},
410+
beforeRouteLeave(to, from, next) {
411+
if (to.name === "community-detail") {
412+
const stateToSave = {
413+
query: this.query,
414+
routeName: from.name,
415+
}
416+
sessionStorage.setItem("communityState", JSON.stringify(stateToSave))
417+
} else {
418+
sessionStorage.removeItem("communityState")
419+
}
420+
next()
421+
},
387422
}
388423
</script>
389424

frontend/src/pages/oj/views/community/PostDetail.vue

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
<div class="contents" v-if="post">
44
<div class="post-header">
55
<div class="title-section" v-if="!isEditing">
6-
<h1 class="post-title">{{ post.title }}</h1>
6+
<div class="sub-title-section">
7+
<h1 class="post-title">
8+
{{ post.title }}
9+
</h1>
10+
<div class="post-actions-always-visible">
11+
<button class="community-back-btn" @click="goback">
12+
{{ $t("m.Community_List") }}
13+
</button>
14+
</div>
15+
</div>
716
<div class="badges-container">
817
<span v-if="isNewPost" class="new-badge">NEW</span>
918
<span
@@ -355,11 +364,22 @@ export default {
355364
editedPostType: "",
356365
editingCommentId: null,
357366
editedCommentContent: "",
367+
prevRoute: null,
358368
}
359369
},
360370
created() {
361371
this.fetchPostDetail()
362372
},
373+
374+
beforeRouteEnter(to, from, next) {
375+
next((vm) => {
376+
const validBoards = ["community", "community-free", "community-question"]
377+
if (from.name && validBoards.includes(from.name)) {
378+
sessionStorage.setItem("last_community_board", from.name)
379+
}
380+
})
381+
},
382+
363383
methods: {
364384
fetchPostDetail() {
365385
this.isLoading = true
@@ -428,6 +448,19 @@ export default {
428448
this.$error("Failed to submit reply.")
429449
})
430450
},
451+
goback() {
452+
const lastBoard = sessionStorage.getItem("last_community_board")
453+
454+
if (lastBoard) {
455+
this.$router.push({ name: lastBoard })
456+
} else {
457+
if (this.post.post_type === "QUESTION") {
458+
this.$router.push({ name: "community-question" })
459+
} else {
460+
this.$router.push({ name: "community" })
461+
}
462+
}
463+
},
431464
enterEditMode() {
432465
this.isEditing = true
433466
this.editedTitle = this.post.title
@@ -667,6 +700,11 @@ main {
667700
margin-bottom: 28px;
668701
}
669702
703+
.sub-title-section {
704+
display: flex;
705+
justify-content: space-between;
706+
}
707+
670708
.post-title {
671709
font-size: 28px;
672710
font-weight: 600;
@@ -786,7 +824,8 @@ main {
786824
.post-delete-btn,
787825
.post-save-btn,
788826
.post-cancel-btn,
789-
.question-status-toggle-btn {
827+
.question-status-toggle-btn,
828+
.community-back-btn {
790829
padding: 8px 16px;
791830
border: none;
792831
border-radius: 8px;
@@ -833,6 +872,18 @@ main {
833872
box-shadow: 0 4px 8px rgba(231, 76, 60, 0.2);
834873
}
835874
875+
.community-back-btn {
876+
background: rgb(241, 243, 244);
877+
color: black;
878+
}
879+
880+
.community-back-btn:hover {
881+
background: lightgrey;
882+
color: rgb(50, 50, 50);
883+
transform: translateY(-1px);
884+
box-shadow: 0 4px 8px rgba(93, 93, 93, 0.2);
885+
}
886+
836887
.post-save-btn {
837888
background: #3498db;
838889
color: white;

0 commit comments

Comments
 (0)