diff --git a/pages/index.tsx b/pages/index.tsx index 5fb6c02..2f8c79a 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -4,7 +4,7 @@ import React, { useEffect, useState } from "react"; import { useLocalStorage } from "utils/useLocalStorage"; import { Village, Topic, Day, Item, Stage } from "types"; import { Drawer } from "@mantine/core"; -import { Paper, Group, Button, Space, Card, Stack } from "@mantine/core"; +import { Paper, Group, Button, Space, Popover } from "@mantine/core"; export interface Filter { day: Day; @@ -12,6 +12,30 @@ export interface Filter { village?: Village[]; } +interface Group { + village: Village; + stage: Stage; + list: Item[]; +} + +const groupByVillageAndStage = (list: Item[]): Group[] => { + const groups = list.reduce>((groups, item) => { + if (!item.stage?.name || !item.village?.name) { + return groups; + } + if (!groups[item.stage.name]) { + groups[item.stage.name] = { + village: item.village.name, + stage: item.stage.name, + list: [], + }; + } + groups[item.stage.name].list.push(item); + return groups; + }, {}); + return Object.values(groups); +}; + const Home: NextPage = () => { const [filter, setFilter] = useLocalStorage("DD_KATLAN_FILTER", { day: Day.tue, @@ -37,42 +61,88 @@ const Home: NextPage = () => { return Math.min(smallest, current.relativeDateInMinutes); }, Infinity) - 30; + const endOfDay = + list.reduce((biggest, current) => { + return Math.max(biggest, current.relativeDateInMinutes + current.duration); + }, 0) - + cutoff + + 60; + + const groups = groupByVillageAndStage(list); + return (
-

{list.length}

- -
    - {list.map((item) => { - console.log(item); +
      + {groups.map((group) => { return (
    • -

      {item.title}

      -
      -

      {item.time?.name}

      -

      {item.duration} perc

      -
      +

      {group.village}

      +

      {group.stage}

      +
        + {group.list.map((item) => { + console.log(item); + return ( +
      • +
        +

        {item.title}

        +
        +

        {item.time?.name}

        +

        {item.duration} perc

        +
        +
        +
      • + ); + })} +
    • ); })}