-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add User Contest in Profile Page & Add Pagination component #291
Conversation
type: Number | ||
}, | ||
limit: { | ||
type: String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
limit
은 어떤 목적으로 사용되는 변수인가요? String
type으로 되어있는데, 아래에는 숫자 연산(/, *)이 있어서 확인 부탁드려요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pagination에 페이지 번호가 최대 몇개 보여질지 나타내는 변수입니다.
총 페이지가 10이고, limit가 3일때 방향키를 누를때마다 (1,2,3), (4,5,6), (7,8,9), (10) 의 페이지가 차례대로 보여요.
b-pagination과 호환되게 코드를 작성하라고 하셔서,
b-pagination의 경우 props를 :limit="3" 가 아닌 limit="3" 문자열으로 받기에 이렇게 코드를 작성했습니다.
javascript상에서 문자열 3과 숫자 3과 동일하다고 들어서 코드의 실행에는 상관이 없지만 혹시 문제가 된다면 바꾸겠습니다 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BootstrapVue 문서 확인해보니까 Number or String
으로 명시되어있는데, 여기도 그렇게 하는 게 나을 것 같아요.
https://bootstrap-vue.org/docs/components/pagination#__BVID__579__row_limit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BootstrapVue 코드도 확인해봤는데, 이렇게 integer로 명시적으로(explicit) 변환하는 함수가 있더라고요.
https://github.com/bootstrap-vue/bootstrap-vue/blob/c645a33790ccaa0e4695dc7b74f9c9d7a812aa8d/src/mixins/pagination.js#L79
const sanitizeLimit = value => {
const limit = toInteger(value) || 1
return limit < 1 ? DEFAULT_LIMIT : limit
}
물론 javascript가 dynamic typed라서 string도 number 연산이 가능하긴 하지만, 이런 암시적인(implicit) 코드를 짜면 어느 부분에서 에러가 날지 예측하기도 어렵고, 가독성도 떨어져서 가급적 지양하는 게 좋아요.
이 부분에서는 computed로 localLimit () { return Number(this.limit) }
처럼 사용하는 게 바람직해 보이네요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수정했어요!
}, | ||
startPage () { | ||
var start = (Math.trunc((this.currentPage - 1) / this.limit)) * this.limit + 1 | ||
return start |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
한 줄로 수정해주세요. 참고로 var
은 가능한 쓰지 않고, 변하지 않는 값은 모두 const
로 고쳐주세요.
return Math.trunc((this.currentPage - 1) / this.limit) * this.limit + 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아하 네
}, | ||
endPage () { | ||
var end = this.startPage + Number(this.limit) - 1 | ||
return end <= this.numberOfPages ? end : this.numberOfPages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return this.startPage + Number(this.limit) - 1 <= this.numberOfPages ? end : this.numberOfPages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이것도 곧 수정하겠습니다
for (let i = this.startPage; i <= this.endPage; i++) { | ||
pages.push(i) | ||
} | ||
return pages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
구글링하다 나온건데, 이렇게 쓰는 게 좀 더 깔끔할 거 같아요.
https://stackoverflow.com/questions/3895478/does-javascript-have-a-method-like-range-to-generate-a-range-within-the-supp
/* this.limit의 type이 Number라면 Number()는 필요 없음 */
return [...Array(Number(this.limit)).keys()].map(i => i + this.startPage)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
만약 페이지 수가 3이고, limit 값이 5이면 오류가 날 수 있을 것 같아요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
한 줄로 고쳤습니다
cursor: pointer; | ||
} | ||
|
||
.page-btn.leftedge { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어차피 scoped style
썼으니까 .page-btn.leftedge
대신에 .leftedge
로 써도 됩니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아래 라인들도 마찬가지입니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수정했습니다
@@ -119,7 +119,7 @@ export default [ | |||
{ | |||
name: 'profile', | |||
path: '/profile', | |||
meta: { requiresAuth: true, title: 'My Profile' }, | |||
meta: { title: 'My Profile' }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분은 왜 수정하셨나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
백엔드 서버 없이 실행하면서 작업하다 보니 (ㅠㅠㅠ) 저부분은 무시해주세요!
@@ -1,38 +1,155 @@ | |||
<script src="./node_modules/chart.js/dist/chart.js"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chart.js 패키지는 NPM으로 설치했으니까, 이 라인은 필요 없습니다. node_modules
에 있는 패키지가 사용될 거에요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수정 부분이 아직 커밋이 안된 거 같은데, 확인 부탁드려요~
type: Number | ||
}, | ||
limit: { | ||
type: String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BootstrapVue 문서 확인해보니까 Number or String
으로 명시되어있는데, 여기도 그렇게 하는 게 나을 것 같아요.
https://bootstrap-vue.org/docs/components/pagination#__BVID__579__row_limit
type: Number | ||
}, | ||
limit: { | ||
type: String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BootstrapVue 코드도 확인해봤는데, 이렇게 integer로 명시적으로(explicit) 변환하는 함수가 있더라고요.
https://github.com/bootstrap-vue/bootstrap-vue/blob/c645a33790ccaa0e4695dc7b74f9c9d7a812aa8d/src/mixins/pagination.js#L79
const sanitizeLimit = value => {
const limit = toInteger(value) || 1
return limit < 1 ? DEFAULT_LIMIT : limit
}
물론 javascript가 dynamic typed라서 string도 number 연산이 가능하긴 하지만, 이런 암시적인(implicit) 코드를 짜면 어느 부분에서 에러가 날지 예측하기도 어렵고, 가독성도 떨어져서 가급적 지양하는 게 좋아요.
이 부분에서는 computed로 localLimit () { return Number(this.limit) }
처럼 사용하는 게 바람직해 보이네요.
1. User Contest Page
What Components have been added?
Things that I have to do next time
2. Pagination
What did I do in Pagination?
How to use
component: {Pagination}
in parent component<Pagination v-model="현재페이지" :total-rows="테이블 전체 행의 개수" :per-page="한 페이지당 나타낼 테이블 행의 개수" limit="한번에 보여질 최대 페이지 번호 개수"></Pagination>
Note that total-rows, per-page, limit are props data
(define currentPage, rows, perPage in data of parent component)
<Pagination v-model="currentPage" :total-rows="rows" :per-page="perPage" limit="5"></Pagination>
THANK YOU XD