Skip to content
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

Feature/subscription sortings #493

Merged
merged 18 commits into from
Apr 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adjust colspan in dependance of window size
  • Loading branch information
EduardZaydler committed Apr 1, 2024
commit 860d1673c53d7ff8baee34ff35f067c2e69f9e89
23 changes: 19 additions & 4 deletions src/Components/SubscriptionList/SubscriptionList.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React from "react";
import React, { useState, useEffect } from "react";
import { Contact } from "../../Domain/Contact";
import { Subscription } from "../../Domain/Subscription";
import { SubscriptionRow } from "./SubscriptionRow/SubscriptionRow";
import ArrowBoldDownIcon from "@skbkontur/react-icons/ArrowBoldDown";
import ArrowBoldUpIcon from "@skbkontur/react-icons/ArrowBoldUp";

import { useSortData } from "../../hooks/useSortData";
import classNames from "classnames/bind";

import styles from "./SubscriptionList.less";
import { useSortData } from "../../hooks/useSortData";

const cn = classNames.bind(styles);

Expand All @@ -25,16 +24,32 @@ export const SubscriptionList: React.FC<Props> = ({
contacts,
handleEditSubscription,
}) => {
const [colspan, setColspan] = useState(2);
const { sortedData, sortConfig, handleSort } = useSortData(subscriptions, "contacts");

// Adjust sort-tags button colspan in dependance of window size
useEffect(() => {
const resize = () => {
const newColspan = window.innerWidth < 600 ? 3 : 2;
setColspan(newColspan);
};

window.addEventListener("resize", resize);
resize();

return () => {
window.removeEventListener("resize", resize);
};
}, []);

const SortingIcon =
sortConfig.direction === "descending" ? <ArrowBoldDownIcon /> : <ArrowBoldUpIcon />;
return (
<div className={cn("items-container")}>
<table ref={tableRef} className={cn("items")}>
<thead>
<tr className={cn("header")}>
<td colSpan={2}>
<td colSpan={colspan}>
<button
onClick={() => handleSort("tags")}
type="button"
Expand Down
Loading