diff --git a/src/shared/components/swipeable-calender/CalendarSlide.tsx b/src/shared/components/swipeable-calender/CalendarSlide.tsx deleted file mode 100644 index 8906630..0000000 --- a/src/shared/components/swipeable-calender/CalendarSlide.tsx +++ /dev/null @@ -1,44 +0,0 @@ -/** @jsxImportSource @emotion/react */ -import { BaseCalendar, CalendarStyleOptions } from "@shared/components/BaseCalendar"; -import { Day, DayFormat } from "@shared/period/day"; -import { Month } from "@shared/period/month"; -import { useCallback } from "react"; - - -interface Props { - month: Month; - tile: (day: Day) => JSX.Element; - onTileClick: (day: Day) => void; - styleOptions?: CalendarStyleOptions; -} -export const CalendarSlide = ({ - month, - tile, - onTileClick, - styleOptions -}: Props) => { - - const tileDisabled = useCallback((day: Day) => { - return day.month !== month.monthNum; - }, [month]); - - return ( - {}} - onTileClick={onTileClick} - tile={tile} - showNavigation={false} - tileDisabled={tileDisabled} - styleOptions={Object.assign({ - tileContainer: { - gap: "0", - }, - tile: { - border: "0.5px solid black", - borderRadius: "0", - } - }, styleOptions)} - /> - ); -}; diff --git a/src/shared/components/swipeable-calender/SwipeableCalendar.tsx b/src/shared/components/swipeable-calender/SwipeableCalendar.tsx index cbeda32..056dc35 100644 --- a/src/shared/components/swipeable-calender/SwipeableCalendar.tsx +++ b/src/shared/components/swipeable-calender/SwipeableCalendar.tsx @@ -3,10 +3,6 @@ import { VirtualSwiper } from "@shared/components/VirtualSwiper"; import { Month } from "@shared/period/month"; import { useCallback, useState } from "react"; import { CalendarNavigation } from "./Nav"; -import { CalendarSlide } from "./CalendarSlide"; -import { useLeaf } from "@shared/view/use-leaf"; -import { Day, DayFormat } from "@shared/period/day"; -import { CalendarStyleOptions } from "../BaseCalendar"; @@ -31,17 +27,13 @@ const getKey = (month: Month) => month.startDay.format() interface Props { month: Month; - onTileClick: (day: Day) => void; - tile: (day: Day) => JSX.Element; + children: (month: Month, index?: number) => React.ReactNode; verticalHeight?: number; - stylesOption?: CalendarStyleOptions; } export const SwipeableCalendar = ({ month: propsMonth, - onTileClick, - tile, + children, verticalHeight, - stylesOption }: Props) => { const [months, setMonths] = useState(loadMonths(propsMonth)); const [activeMonth, setActiveMonth] = useState(propsMonth); @@ -71,14 +63,7 @@ export const SwipeableCalendar = ({ onSlideChange={onSlideChange} verticalHeight={verticalHeight} > - {(month) => ( - - )} + {children} ) diff --git a/src/widgets/calendar/ui/CalendarSlide.tsx b/src/widgets/calendar/ui/CalendarSlide.tsx new file mode 100644 index 0000000..97cc926 --- /dev/null +++ b/src/widgets/calendar/ui/CalendarSlide.tsx @@ -0,0 +1,69 @@ +/** @jsxImportSource @emotion/react */ +import { Task } from "@entities/note"; +import { BaseCalendar } from "@shared/components/BaseCalendar"; +import { Day } from "@shared/period/day"; +import { Month } from "@shared/period/month"; +import { useAsync } from "@shared/utils/use-async"; +import { useCallback, useMemo } from "react"; +import { CalendarTile } from "./CalendarTile"; +import { loadCalendar } from "../model/load-calendar"; +import { Tile } from "../model/types"; +import { useTabRoute } from "@shared/tab/use-tab-route"; + + +interface CalendarSlideProps { + month: Month; +} +export const CalendarSlide = ({ month }: CalendarSlideProps) => { + const calendarAsync = useAsync(async () => await loadCalendar(month), [month]); + const route = useTabRoute(s=>s.route); + + const tiles = useMemo>(() => { + if(calendarAsync.value) { + return calendarAsync.value.tiles; + } else { + return new Map(); + } + }, [calendarAsync.value]); + + + const tile = useCallback((day: Day) => { + let tile = { + day, + tasks: [] as Task[] + }; + tile = tiles.get(day.format()) || tile; + return ; + }, [tiles]); + + + const tileDisabled = useCallback((day: Day) => { + return day.month !== month.monthNum; + }, [month]); + + const onTileClick = useCallback((day: Day) => { + route("note", { day }); + }, [route]); + + + if (calendarAsync.loading) return
Loading...
; + return ( + {}} + onTileClick={onTileClick} + tile={tile} + showNavigation={false} + tileDisabled={tileDisabled} + styleOptions={{ + tileContainer: { + gap: "0", + }, + tile: { + border: "0.5px solid black", + borderRadius: "0", + } + }} + /> + ); +}; diff --git a/src/widgets/calendar/ui/CalendarTile.tsx b/src/widgets/calendar/ui/CalendarTile.tsx index 40d0676..0cdbde8 100644 --- a/src/widgets/calendar/ui/CalendarTile.tsx +++ b/src/widgets/calendar/ui/CalendarTile.tsx @@ -1,6 +1,6 @@ /** @jsxImportSource @emotion/react */ import { Day } from "@shared/period/day"; -import { Tile } from "../model/types" +import { Tile } from "../model/load-tile-map"; import { TEXT_CSS } from "@shared/components/text-style"; import { Task } from "@entities/note"; import { css } from "@emotion/react"; diff --git a/src/widgets/calendar/ui/CalendarWidget.tsx b/src/widgets/calendar/ui/CalendarWidget.tsx index fd5de52..849a025 100644 --- a/src/widgets/calendar/ui/CalendarWidget.tsx +++ b/src/widgets/calendar/ui/CalendarWidget.tsx @@ -4,47 +4,34 @@ import { useCallback, useMemo, useState } from "react"; import { useLeaf } from "@shared/view/use-leaf"; import { SwipeableCalendar } from "@shared/components/swipeable-calender/SwipeableCalendar"; import { useAsync } from "@shared/utils/use-async"; -import { loadCalendar } from "../model/load-calendar"; +import { loadTileMap } from "../model/load-tile-map"; import { useTabRoute } from "@shared/tab/use-tab-route"; import { Day } from "@shared/period/day"; import { CalendarTile } from "./CalendarTile"; import { Task } from "@entities/note"; import { useTabHeight } from "@app/ui/use-tab-height"; import { TileHeightInfoProvider } from "./tile-height-info-context"; +import { CalendarSlide } from "./CalendarSlide"; type Props = { month: Month; } export const CalendarWidget = ({ month }: Props) => { - // const leafBgColor = useLeaf(s=>s.leafBgColor); - const calendarAsync = useAsync(async () => await loadCalendar(month), [month]); - const route = useTabRoute(s=>s.route); const tabHeight = useTabHeight(); - - const renderTile = useCallback((day: Day) => { - let tile = { - day, - tasks: [] as Task[] - }; - tile = calendarAsync.value?.tiles.get(day.format()) || tile; - return ; - }, [calendarAsync.value?.tiles]); - - const onTileClick = useCallback((day: Day) => { - route("note", { day }); - }, [route]); - - if(!calendarAsync.value || calendarAsync.loading) return
Loading...
; return ( + > + {month => ( + + )} + ) diff --git a/src/widgets/note-achivement/ui/CalendarSlide.tsx b/src/widgets/note-achivement/ui/CalendarSlide.tsx new file mode 100644 index 0000000..84cc331 --- /dev/null +++ b/src/widgets/note-achivement/ui/CalendarSlide.tsx @@ -0,0 +1,62 @@ +/** @jsxImportSource @emotion/react */ +import { NoteEntity, noteRepository, Task } from "@entities/note"; +import { BaseCalendar } from "@shared/components/BaseCalendar"; +import { Day } from "@shared/period/day"; +import { Month } from "@shared/period/month"; +import { useAsync } from "@shared/utils/use-async"; +import { useCallback, useMemo } from "react"; +import { useTabRoute } from "@shared/tab/use-tab-route"; +import { PerformanceCircle } from "@features/performance"; + + +interface CalendarSlideProps { + month: Month; +} +export const CalendarSlide = ({ month }: CalendarSlideProps) => { + const notesAsync = useAsync(async () => await noteRepository.loadBetween(month.startDay, month.endDay), [month]); + const route = useTabRoute(s=>s.route); + + const tile = useCallback((tileDay: Day) => { + let performance = NoteEntity.getEmptyNotePerformance(); + if(notesAsync.value){ + const note = notesAsync.value.find(note => note.day.isSameDay(tileDay)); + if(note){ + performance = NoteEntity.getPerformance(note); + } + } + return ( + + ) + }, [notesAsync.value]); + + + const onTileClick = useCallback((day: Day) => { + route("note", { day }); + }, [route]); + + + const tileDisabled = useCallback((day: Day) => { + return day.month !== month.monthNum; + }, [month]); + + + if(notesAsync.loading) return
Loading...
; + return ( + {}} + onTileClick={onTileClick} + tile={tile} + showNavigation={false} + tileDisabled={tileDisabled} + styleOptions={{ + tileContainer: { + gap: "0", + }, + tile: { + border: "0" + } + }} + /> + ); +};