Skip to content

Commit 1ca47ac

Browse files
authored
Merge pull request #14 from webdevia/homework-7
Fix linter errors
2 parents f71dea0 + cfce58a commit 1ca47ac

File tree

9 files changed

+86
-92
lines changed

9 files changed

+86
-92
lines changed

src/homeworks/homework-10/AccountService.test.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,13 @@ describe('AccountService', () => {
3131
});
3232

3333
test('should throw table not found error', async () => {
34+
let err;
3435
try {
3536
await accountService.userDiscount.loadDiscounts();
3637
} catch (e) {
37-
expect(e.message).toBe('Failed to load user_discount discounts');
38-
}
39-
});
40-
41-
test('should throw table not found error', async () => {
42-
try {
43-
await accountService.userDiscount.loadDiscounts();
44-
} catch (e) {
45-
expect(e.message).toBe('Failed to load user_discount discounts');
38+
err = e;
39+
} finally {
40+
expect(err.message).toBe('Failed to load user_discount discounts');
4641
}
4742
});
4843

src/homeworks/homework-10/Database.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class Database implements IDatabase {
1313
save<T>(key: string, value: T): Promise<boolean> {
1414
return new Promise((resolve) =>
1515
setTimeout(() => {
16-
resolve(!!this.data.set(key, value));
16+
resolve(!!this.data.set(key, value));
1717
}, 500)
1818
);
1919
}
@@ -30,4 +30,4 @@ export class Database implements IDatabase {
3030
}, 500)
3131
);
3232
}
33-
}
33+
}
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
export enum User {
2-
Standard = 'Standard',
3-
Premium = 'Premium',
4-
Gold = 'Gold',
5-
Free = 'Free',
6-
}
7-
8-
export enum Product {
9-
Car = 'Car',
10-
Toy = 'Toy',
11-
Food = 'Food',
12-
}
13-
2+
Standard = 'Standard',
3+
Premium = 'Premium',
4+
Gold = 'Gold',
5+
Free = 'Free',
6+
}
7+
8+
export enum Product {
9+
Car = 'Car',
10+
Toy = 'Toy',
11+
Food = 'Food',
12+
}

src/pages/ProductForm/ProductForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const ProductForm = () => {
2424

2525
return (
2626
<RegularForm onSubmit={handleSubmit(onSubmit)}>
27-
<RegularForm.Title>Товар</RegularForm.Title>
27+
<RegularForm.Title>Товар</RegularForm.Title>
2828
<FormInputField name="name" register={register} type="text" errors={errors.name}>
2929
Название
3030
</FormInputField>

src/shared/collapse/Collapse.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type CollapseProps = {
99

1010
export const Collapse: React.FC<CollapseProps> = ({ title, children }) => {
1111
const [isOpen, setIsOpen] = useState(false);
12-
const { height, contentRef } = useCollapseHeight(isOpen);
12+
const { height, contentRef } = useCollapseHeight();
1313

1414
const toggleCollapse = () => {
1515
setIsOpen((prev) => !prev);
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import React, { useEffect, useRef, useState } from "react";
1+
import React, { useEffect, useRef, useState } from 'react';
22

3-
export const useCollapseHeight = (isOpen: boolean) => {
4-
const [height, setHeight] = useState(0);
5-
const contentRef = useRef<HTMLDivElement>(null);
6-
7-
useEffect(() => {
8-
const resizeObserver = new ResizeObserver((entries) => {
9-
entries.forEach((entry) => setHeight(entry.borderBoxSize[0].blockSize));
10-
});
11-
12-
const currentContentRef = contentRef.current;
13-
3+
export const useCollapseHeight = () => {
4+
const [height, setHeight] = useState(0);
5+
const contentRef = useRef<HTMLDivElement>(null);
6+
7+
useEffect(() => {
8+
const resizeObserver = new ResizeObserver((entries) => {
9+
entries.forEach((entry) => setHeight(entry.borderBoxSize[0].blockSize));
10+
});
11+
12+
const currentContentRef = contentRef.current;
13+
14+
if (currentContentRef) {
15+
resizeObserver.observe(currentContentRef);
16+
}
17+
18+
return () => {
1419
if (currentContentRef) {
15-
resizeObserver.observe(currentContentRef);
20+
resizeObserver.unobserve(currentContentRef);
1621
}
17-
18-
return () => {
19-
if (currentContentRef) {
20-
resizeObserver.unobserve(currentContentRef);
21-
}
22-
};
23-
}, []);
24-
25-
return { height, contentRef };
26-
};
22+
};
23+
}, []);
24+
25+
return { height, contentRef };
26+
};

src/shared/tooltip-buttons/TooltipButtons.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { ReactNode } from 'react';
22
import { Position } from '../tooltip/utils/tooltipPosition';
3-
import {Tooltip} from "../tooltip/Tooltip";
3+
import { Tooltip } from '../tooltip/Tooltip';
44
import { Button } from '../button/Button';
55
import s from './TooltipButtons.module.scss';
66

src/shared/tooltip/hooks/useTooltip.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState, useRef, useLayoutEffect } from 'react';
22
import { positionMap, Position } from '../utils/tooltipPosition';
33

4-
export const useTooltip = (position: Position = 'bottom', duration: number = 1000) => {
4+
export const useTooltip = (position: Position = 'bottom', duration = 1000) => {
55
const [visible, setVisible] = useState(false);
66
const [mounted, setMounted] = useState(false);
77
const [coords, setCoords] = useState({ top: 0, left: 0 });
@@ -56,4 +56,4 @@ export const useTooltip = (position: Position = 'bottom', duration: number = 100
5656
handleMouseEnter,
5757
handleMouseLeave,
5858
};
59-
};
59+
};
Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
type Coords = {
2-
top: number;
3-
left: number;
4-
};
5-
6-
type CoordProps = {
7-
targetRect: DOMRect;
8-
tooltipRect: DOMRect;
9-
offset: number;
10-
};
11-
12-
export type Position = 'top' | 'bottom' | 'left' | 'right';
13-
14-
const getCenterCoord = (primary: number, secondary: number) => (primary - secondary) / 2;
15-
16-
const YLeft = (primary: DOMRect, secondary: DOMRect) =>
17-
primary.left + window.scrollX + getCenterCoord(primary.width, secondary.width);
18-
19-
const XTop = (primary: DOMRect, secondary: DOMRect) =>
20-
primary.top + window.scrollY + getCenterCoord(primary.height, secondary.height);
21-
22-
export const positionMap: Record<Position, (props: CoordProps) => Coords> = {
23-
top: ({ targetRect, tooltipRect, offset }) => ({
24-
top: targetRect.top + window.scrollY - tooltipRect.height - offset,
25-
left: targetRect.left + window.scrollX + getCenterCoord(targetRect.width, tooltipRect.width),
26-
}),
27-
28-
bottom: ({ targetRect, tooltipRect, offset }) => ({
29-
top: targetRect.bottom + window.scrollY + offset,
30-
left: YLeft(targetRect, tooltipRect),
31-
}),
32-
33-
left: ({ targetRect, tooltipRect, offset }) => ({
34-
top: XTop(targetRect, tooltipRect),
35-
left: targetRect.left + window.scrollX - tooltipRect.width - offset,
36-
}),
37-
38-
right: ({ targetRect, tooltipRect, offset }) => ({
39-
top: XTop(targetRect, tooltipRect),
40-
left: targetRect.left + window.scrollX + targetRect.width + offset,
41-
}),
42-
};
2+
top: number;
3+
left: number;
4+
};
5+
6+
type CoordProps = {
7+
targetRect: DOMRect;
8+
tooltipRect: DOMRect;
9+
offset: number;
10+
};
11+
12+
export type Position = 'top' | 'bottom' | 'left' | 'right';
13+
14+
const getCenterCoord = (primary: number, secondary: number) => (primary - secondary) / 2;
15+
16+
const YLeft = (primary: DOMRect, secondary: DOMRect) =>
17+
primary.left + window.scrollX + getCenterCoord(primary.width, secondary.width);
18+
19+
const XTop = (primary: DOMRect, secondary: DOMRect) =>
20+
primary.top + window.scrollY + getCenterCoord(primary.height, secondary.height);
21+
22+
export const positionMap: Record<Position, (props: CoordProps) => Coords> = {
23+
top: ({ targetRect, tooltipRect, offset }) => ({
24+
top: targetRect.top + window.scrollY - tooltipRect.height - offset,
25+
left: targetRect.left + window.scrollX + getCenterCoord(targetRect.width, tooltipRect.width),
26+
}),
27+
28+
bottom: ({ targetRect, tooltipRect, offset }) => ({
29+
top: targetRect.bottom + window.scrollY + offset,
30+
left: YLeft(targetRect, tooltipRect),
31+
}),
32+
33+
left: ({ targetRect, tooltipRect, offset }) => ({
34+
top: XTop(targetRect, tooltipRect),
35+
left: targetRect.left + window.scrollX - tooltipRect.width - offset,
36+
}),
37+
38+
right: ({ targetRect, tooltipRect, offset }) => ({
39+
top: XTop(targetRect, tooltipRect),
40+
left: targetRect.left + window.scrollX + targetRect.width + offset,
41+
}),
42+
};

0 commit comments

Comments
 (0)