-
+ {chekError === TypeErroros.start && visiblePeoples.length > 0 && (
+
+ )}
-
+ {chekError === TypeErroros.waitLoading &&
}
-
Something went wrong
+ {chekError === TypeErroros.loadingError && (
+
+ Something went wrong
+
+ )}
-
There are no people on the server
+ {chekError === TypeErroros.noPeople && peoples.length === 0 && (
+
+ There are no people on the server
+
+ )}
-
There are no people matching the current search criteria
+ {chekError === TypeErroros.noPeopleSearch && (
+
There are no people matching the current search criteria
+ )}
-
+ {chekError === TypeErroros.start && visiblePeoples.length > 0 && (
+
+ )}
diff --git a/src/components/PeopleTable.tsx b/src/components/PeopleTable.tsx
index fdd814b4a..4a49ffe3c 100644
--- a/src/components/PeopleTable.tsx
+++ b/src/components/PeopleTable.tsx
@@ -1,5 +1,84 @@
+import classNames from 'classnames';
+import { Person } from '../types';
+import { PersonLink } from './PersonLink';
+import { useParams, useSearchParams } from 'react-router-dom';
+import { useEffect, useState } from 'react';
+
/* eslint-disable jsx-a11y/control-has-associated-label */
-export const PeopleTable = () => {
+type Props = {
+ peoples: Person[];
+ onFilter: (persons: Person[]) => void;
+};
+
+export const PeopleTable = ({ peoples, onFilter }: Props) => {
+ const [serchParams, setSerchParams] = useSearchParams();
+ const { peopleSlug } = useParams();
+ const [masPeople, setMasPeople] = useState(peoples);
+ let currentSort = serchParams.get('sort') as keyof Person | null;
+ let currentOrder = serchParams.get('order') as 'desc' | null;
+
+ useEffect(() => {
+ setMasPeople(peoples);
+ }, [peoples]);
+ function findParenth(parenthName: string) {
+ const parenth = peoples.find(human => human.name === parenthName);
+
+ if (parenth) {
+ return
;
+ }
+
+ return parenthName;
+ }
+
+ function sortPeople(field: keyof Person | null, order: 'desc' | null) {
+ const sorted = [...peoples];
+
+ if (field === null) {
+ return setMasPeople([...peoples]);
+ }
+
+ sorted.sort((a, b) => {
+ const valA = a[field];
+ const valB = b[field];
+
+ if (typeof valA === 'string' && typeof valB === 'string') {
+ return order !== null
+ ? valB.localeCompare(valA)
+ : valA.localeCompare(valB);
+ }
+
+ if (typeof valA === 'number' && typeof valB === 'number') {
+ return order !== null ? valB - valA : valA - valB;
+ }
+
+ return 0;
+ });
+
+ setMasPeople(sorted);
+ onFilter(sorted);
+ }
+
+ function hangelSort(sor: string) {
+ const params = new URLSearchParams(serchParams);
+
+ if (currentSort === sor && currentOrder === 'desc') {
+ params.delete('sort');
+ params.delete('order');
+ } else if (currentSort === sor) {
+ params.set('order', 'desc');
+ } else {
+ params.set('sort', sor);
+ params.delete('order');
+ }
+
+ currentSort = params.get('sort') as keyof Person | null;
+ currentOrder = params.get('order') as 'desc' | null;
+ setSerchParams(params);
+ sortPeople(currentSort, currentOrder);
+
+ return;
+ }
+
return (
);
diff --git a/src/components/PersonLink.tsx b/src/components/PersonLink.tsx
new file mode 100644
index 000000000..4ceed9ec9
--- /dev/null
+++ b/src/components/PersonLink.tsx
@@ -0,0 +1,23 @@
+import classNames from 'classnames';
+import { Link, useLocation } from 'react-router-dom';
+import { Person } from '../types';
+
+type Props = {
+ person: Person;
+};
+
+export const PersonLink = ({ person }: Props) => {
+ const location = useLocation();
+
+ return (
+
+ {person.name}
+
+ );
+};
diff --git a/src/components/SearchLink.tsx b/src/components/SearchLink.tsx
index f78b83cbc..1afbc3fb5 100644
--- a/src/components/SearchLink.tsx
+++ b/src/components/SearchLink.tsx
@@ -2,21 +2,21 @@ import { Link, LinkProps, useSearchParams } from 'react-router-dom';
import { getSearchWith, SearchParams } from '../utils/searchHelper';
/**
- * To replace the the standard `Link` we take all it props except for `to`
- * along with the custom `params` prop that we use for updating the search
+ * Щоб замінити стандартне `Link`, ми беремо всі його властивості, крім `to`
+ * разом із власною властивістю `params`, яку ми використовуємо для оновлення пошуку
*/
type Props = Omit
& {
params: SearchParams;
};
/**
- * SearchLink updates the given `params` in the search keeping the `pathname`
- * and the other existing search params (see `getSearchWith`)
+ * SearchLink оновлює задані `params` у пошуку, зберігаючи `pathname`
+ * та інші існуючі параметри пошуку (див. `getSearchWith`)
*/
export const SearchLink: React.FC = ({
- children, // this is the content between the open and closing tags
- params, // the params to be updated in the `search`
- ...props // all usual Link props like `className`, `style` and `id`
+ children, // це вміст між відкриваючим та закриваючим тегами
+ params, // параметри, які потрібно оновити в `search`
+ ...props // усі звичайні властивості посилань, такі як `className`, `style` та `id`
}) => {
const [searchParams] = useSearchParams();
@@ -28,7 +28,7 @@ export const SearchLink: React.FC = ({
to={{
search: getSearchWith(searchParams, params),
}}
- {...props} // copy all the other props
+ {...props} // скопіювати всі інші пропси
>
{children}
diff --git a/src/constants/Error.ts b/src/constants/Error.ts
new file mode 100644
index 000000000..15c216870
--- /dev/null
+++ b/src/constants/Error.ts
@@ -0,0 +1,7 @@
+export enum TypeErroros {
+ start = 'null',
+ waitLoading = '',
+ loadingError = 'loadingError',
+ noPeople = 'noPeople',
+ noPeopleSearch = 'noPeopleSearch',
+}
diff --git a/src/index.tsx b/src/index.tsx
index d72ba5730..0082c2d81 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -1,13 +1,8 @@
import { createRoot } from 'react-dom/client';
-import { HashRouter as Router } from 'react-router-dom';
import 'bulma/css/bulma.css';
import '@fortawesome/fontawesome-free/css/all.css';
-import { App } from './App';
+import { Root } from './Root';
-createRoot(document.getElementById('root') as HTMLDivElement).render(
-
-
- ,
-);
+createRoot(document.getElementById('root') as HTMLDivElement).render();