Skip to content

Commit

Permalink
refactor(addon-mobile): support noUncheckedIndexedAccess (#8717)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Aug 29, 2024
1 parent fd159e0 commit dc75d3d
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {NgIf} from '@angular/common';
import {ChangeDetectionStrategy, Component, inject} from '@angular/core';
import {TuiRipple} from '@taiga-ui/addon-mobile/directives';
import {TuiLet} from '@taiga-ui/cdk/directives/let';
Expand All @@ -9,7 +10,7 @@ import {TuiCalendarSheetPipe} from '@taiga-ui/core/pipes/calendar-sheet';
@Component({
standalone: true,
selector: 'tui-mobile-calendar-sheet',
imports: [TuiLet, TuiCalendarSheetPipe, TuiRepeatTimes, TuiRipple],
imports: [TuiLet, TuiCalendarSheetPipe, TuiRepeatTimes, TuiRipple, NgIf],
templateUrl: './mobile-calendar-sheet.template.html',
styleUrls: ['./mobile-calendar-sheet.style.less'],
changeDetection: ChangeDetectionStrategy.OnPush,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
automation-id="tui-primitive-calendar-mobile__row"
class="t-row"
>
<div
*tuiRepeatTimes="let colIndex of sheet[rowIndex].length"
automation-id="tui-primitive-calendar-mobile__cell"
tuiRipple
class="t-cell"
[attr.data-range]="getItemRange(sheet[rowIndex][colIndex])"
[class.t-cell_disabled]="disabledItemHandler(sheet[rowIndex][colIndex])"
[class.t-cell_interval]="itemIsInterval(sheet[rowIndex][colIndex])"
[class.t-cell_today]="itemIsToday(sheet[rowIndex][colIndex])"
(click)="onItemClick(sheet[rowIndex][colIndex])"
>
{{ sheet[rowIndex][colIndex].day }}
</div>
<ng-container *tuiRepeatTimes="let colIndex of sheet[rowIndex]?.length ?? 0">
<div
*ngIf="sheet[rowIndex]?.[colIndex] as item"
automation-id="tui-primitive-calendar-mobile__cell"
tuiRipple
class="t-cell"
[attr.data-range]="getItemRange(item)"
[class.t-cell_disabled]="disabledItemHandler(item)"
[class.t-cell_interval]="itemIsInterval(item)"
[class.t-cell_today]="itemIsToday(item)"
(click)="onItemClick(item)"
>
{{ item.day }}
</div>
</ng-container>
</div>
</ng-container>
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ export class TuiMobileCalendarStrategy implements VirtualScrollStrategy {
let accumulator = 0;

for (let year = 0; year < cycle.length; year++) {
for (let month = 0; month < cycle[year].length; month++) {
accumulator += cycle[year][month];
for (let month = 0; month < (cycle[year]?.length ?? 0); month++) {
accumulator += cycle[year]?.[month] ?? 0;

if (accumulator - cycle[year][month] / 2 > remainder) {
if (accumulator - (cycle[year]?.[month] ?? 0) / 2 > remainder) {
return Math.max((years + year) * MONTHS_IN_YEAR + month, 0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ export class TuiPullToRefreshService extends Observable<number> {
!this.scrollRef.nativeElement.scrollTop &&
!this.el.querySelector(EXCLUSION_SELECTORS),
),
map(({touches}) => touches[0].clientY),
map(({touches}) => touches[0]?.clientY ?? 0),
switchMap((start) =>
tuiTypedFromEvent(this.el, 'touchmove').pipe(
tap((): void => {
this.touched = true;
}),
map(({touches}) => touches[0].clientY - start),
map(({touches}) => (touches[0]?.clientY ?? 0) - start),
filter((distance) => distance > 0),
takeUntil(
tuiTypedFromEvent(this.el, 'touchend').pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ export class TuiSheetDialogComponent<I> implements AfterViewInit {
inject<TuiPopover<TuiSheetDialogOptions<I>, any>>(POLYMORPHEUS_CONTEXT);

public ngAfterViewInit(): void {
this.el.scrollTop = [...this.getStops(this.stopsRefs), this.sheetTop][
this.context.initial
];
this.el.scrollTop =
[...this.getStops(this.stopsRefs), this.sheetTop][this.context.initial] ?? 0;
}

protected get offset(): number {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<div
class="t-actions"
(waResizeObserver)="onResize($event[0])"
(waResizeObserver)="$event[0] && onResize($event[0])"
>
<ng-content select="[tuiSwipeAction]" />
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class TuiDropdownMobileComponent implements OnDestroy, AfterViewInit {
}
}

protected onIntersection([{isIntersecting}]: IntersectionObserverEntry[]): void {
protected onIntersection({isIntersecting}: IntersectionObserverEntry): void {
if (isIntersecting) {
this.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
waIntersectionThreshold="1"
class="t-filler"
(touchstart.prevent)="close()"
(waIntersectionObservee)="onIntersection($event)"
(waIntersectionObservee)="$event[0] && onIntersection($event[0])"
></div>
<div
#container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ const STYLE = {

export function tuiFindTouchIndex(touches: TouchList, id: number): number {
for (let i = 0; i < touches.length; i++) {
const {identifier} = touches[i];

if (identifier === id) {
if (touches[i]?.identifier === id) {
return i;
}
}
Expand All @@ -42,12 +40,12 @@ export class TuiTouchable {
tuiTypedFromEvent(this.el, 'touchstart', {passive: true})
.pipe(
tap(() => this.onTouchStart()),
map(({touches}) => touches[touches.length - 1].identifier),
map(({touches}) => touches[touches.length - 1]?.identifier),
switchMap((identifier) =>
race(
tuiTypedFromEvent(this.el, 'touchmove', {passive: true}).pipe(
filter(({touches}) =>
this.hasTouchLeft(this.el, touches, identifier),
this.hasTouchLeft(this.el, touches, identifier ?? 0),
),
),
tuiTypedFromEvent(this.el, 'touchend'),
Expand Down Expand Up @@ -78,7 +76,7 @@ export class TuiTouchable {
return true;
}

const {clientX, clientY} = touches[id];
const {clientX = 0, clientY = 0} = touches[id] ?? {};

return !element.contains(ownerDocument.elementFromPoint(clientX, clientY));
}
Expand Down

0 comments on commit dc75d3d

Please sign in to comment.