Skip to content

Commit

Permalink
Merge pull request #57 from eMerzh/sort_field
Browse files Browse the repository at this point in the history
chore: type sort field
  • Loading branch information
h16nning authored Feb 13, 2024
2 parents bf2a0be + 7612a5b commit 6625172
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/components/CardManagerView/CardManagerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IconSearch } from "@tabler/icons-react";
import { useState } from "react";
import { Outlet, useLocation, useNavigate, useParams } from "react-router-dom";
import { useCardsWith } from "../../logic/card";
import selectCards from "../../logic/card_filter";
import selectCards, { SortField } from "../../logic/card_filter";
import { useDecks } from "../../logic/deck";
import CardTable from "../CardTable/CardTable";
import { AppHeaderContent } from "../Header/Header";
Expand All @@ -26,7 +26,7 @@ function CardManagerView() {

const [filter, setFilter] = useDebouncedState<string>("", 250);

const [sort, setSort] = useState<[string, boolean]>(["front", true]);
const [sort, setSort] = useState<[SortField, boolean]>(["front", true]);

const [cards] = useCardsWith(
(cards) => selectCards(cards, deckId, filter, sort),
Expand Down
5 changes: 3 additions & 2 deletions src/components/CardTable/CardTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import { Table, Text } from "@mantine/core";
import { useEventListener } from "@mantine/hooks";
import CardTableHeadItem from "./CardTableHeadItem";
import { CardTableItem } from "./CardTableItem";
import { SortField } from "../../logic/card_filter";

interface CardTableProps {
cardSet: Card<CardType>[];
selectedIndex: number | undefined;
setSelectedIndex: (index: number) => void;
selectedCard: Card<CardType> | undefined;
setSelectedCard: (card: Card<CardType>) => void;
sort: [string, boolean];
setSort: (sort: [string, boolean]) => void;
sort: [SortField, boolean];
setSort: (sort: [SortField, boolean]) => void;
}

function CardTable({
Expand Down
7 changes: 4 additions & 3 deletions src/components/CardTable/CardTableHeadItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import cx from "clsx";
import React from "react";
import { Box, Table } from "@mantine/core";
import { IconArrowUp } from "@tabler/icons-react";
import { SortField } from "../../logic/card_filter";

interface CardTableHeadItemProps {
name: string;
id: string;
sort: [string, boolean];
setSort: (sort: [string, boolean]) => void;
id: SortField;
sort: [SortField, boolean];
setSort: (sort: [SortField, boolean]) => void;
}

export default function CardTableHeadItem({
Expand Down
4 changes: 3 additions & 1 deletion src/logic/card_filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { Card, CardType, getCardsOf } from "./card";
import { getUtils } from "./CardTypeManager";
import { getDeck } from "./deck";

export type SortField = "front" | "creation_date" | "deck" | "type";

export default async function selectCards(
cards: Table<Card<CardType>>,
deckId: string | undefined,
filter: string,
sort: [string, boolean]
sort: [SortField, boolean]
): Promise<Card<CardType>[] | undefined> {
let filteredCards:
| Table<Card<CardType>>
Expand Down

0 comments on commit 6625172

Please sign in to comment.