Skip to content

feat: реализовал пагинацию #86

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

Open
wants to merge 1 commit into
base: lecture-6
Choose a base branch
from

Conversation

aleksUkolov
Copy link

No description provided.

Copy link
Owner

@Letto228 Letto228 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Привет!
В целом все гуд 👍
Есть пару комментариев по логике, и несколько вопросов, посмотри, пожалуйста. Буду очень ждать твоего фидбека!

<button mat-icon-button (click)="back()">
<mat-icon>chevron_left</mat-icon>
</button>
<button mat-button *ngFor="let pageIndex of pageIndexes; let index=index" ngClass="{{activeIndex == index ? 'active' : ''}}" (click)="go(index)">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Почему использовал ngClass, а не [class.active]=activeIndex == index?
  2. Почему решил использовать сравнение с приведением типов (==), а не строгое сравнение (===)?
  3. Почему решил использовать интерполяцию?

@@ -0,0 +1,8 @@
export interface IPaginationContext<T> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я бы добавил еще appPaginationOf для того, чтобы передавать значение инпута в контексте. Поддержим функциональность используемую в стандартных структурных директивах)

selector: '[appPagination]'
})
export class PaginationDirective<T> implements OnChanges, OnInit{
@Input() appPaginationOf!: T[]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему решил использовать !:? Почему не стар расширять интерфейс до | null | undefined, чтобы выходные данные были погибче и можно было работать без обертки в виде ngIf?

}

ngOnInit() {
this.pageCount = this.appPaginationOf ? Math.ceil(this.appPaginationOf?.length/this.appPaginationChankSize) : 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Значение собирается из входных данных. Согласен, что они могут измениться? Может стоит реагируя на входные данные - обновлять значение на основе которых собирается контекст?

А нужен ли в this.appPaginationOf?.length optional chaining ?.?

}

private getCurrentContext(currentPageIndex: number): IPaginationContext<T[]> {
const startPosition:number = this.appPaginationChankSize*currentPageIndex || 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему тут поставил явную типзацию, а ниже нет?
Мне видится, что типизация нигдене нужна, т.к. наследование типов для констант в данном случае работает отлично

private getCurrentContext(currentPageIndex: number): IPaginationContext<T[]> {
const startPosition:number = this.appPaginationChankSize*currentPageIndex || 0;
const chankSize = this.appPaginationChankSize || 0;
const chankCards= this.appPaginationOf?.slice(startPosition, startPosition + chankSize);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вроде appPaginationOf указан как !: T[], зачем нам тогда тут ?.?


private next() {
if(this.currentPageIndex$.value + 1 < this.pageCount){
const nextIndex = this.currentPageIndex$.value + 1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Несколько раз вычисляется this.currentPageIndex$.value + 1 может стоит константу вынести до if?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В back аналогично

private next() {
if(this.currentPageIndex$.value + 1 < this.pageCount){
const nextIndex = this.currentPageIndex$.value + 1;
const newIndex = nextIndex < this.appPaginationOf!.length ? nextIndex : 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nextIndex < this.appPaginationOf!.length - а валидна ли теперь данная проверка? Кажется, для данной реализации функциональность зацикливания совсем ни к чему и ее можно убрать

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В back аалогично


if (shouldShowItems) {
this.currentPageIndex$.next(0);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А return не стоит ли тут добавить? Не будет ли бага при изменении входного массива, что увидим пустую страницу?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants