diff --git a/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/DreamsProvider.tsx b/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/DreamsProvider.tsx index 0ad82b8..aff4544 100644 --- a/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/DreamsProvider.tsx +++ b/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/DreamsProvider.tsx @@ -1,11 +1,15 @@ "use client" import {FC, PropsWithChildren} from "react"; -import useDreams, {DreamsState} from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/hooks/useDreams"; +import useDreams, { + DreamsState +} from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/hooks/useDreams"; import useDreamCharacters, { DreamCharactersState } from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/hooks/useDreamCharacters"; -import useDreamTags, {DreamTagsState} from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/hooks/useDreamTags"; +import useDreamTags, { + DreamTagsState +} from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/hooks/useDreamTags"; import {createDataContext, DataContextProps} from "@/utils/client/client-data-utils"; interface DreamsContextProps extends DataContextProps { @@ -15,6 +19,9 @@ interface DreamsContextProps extends DataContextProps { } const [DreamsContext, useHook] = createDataContext("useDreamsData must be used in a DreamsProvider!") +const [UserDreamsContext, useUserDreamsHook] = createDataContext("useUserDreams must be used in a UserDreamsProvider!") +const [UserDreamTagsContext, useUserDreamTagsHook] = createDataContext("useUserDreamTags must be used in a UserDreamTagsProvider!") +const [UserDreamCharactersContext, useUserDreamCharactersHook] = createDataContext("useUserDreamCharacters must be used in a UserDreamCharactersProvider!") const DreamsProvider: FC = ({children}) => { const dreams = useDreams() @@ -23,10 +30,19 @@ const DreamsProvider: FC = ({children}) => { return ( - {children} + + + + {children} + + + ) } export default DreamsProvider -export const useDreamsData = useHook \ No newline at end of file +export const useDreamsData = useHook +export const useUserDreams = useUserDreamsHook +export const useUserDreamTags = useUserDreamTagsHook +export const useUserDreamCharacters = useUserDreamCharactersHook diff --git a/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/card/DreamCard.tsx b/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/card/DreamCard.tsx index f2915f5..84fb0ac 100644 --- a/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/card/DreamCard.tsx +++ b/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/card/DreamCard.tsx @@ -1,7 +1,7 @@ "use client" import {FC, Fragment, useCallback, useState} from "react"; -import {Dream, DreamCharacter, DreamTag} from "@prisma/client"; +import {Dream} from "@prisma/client"; import {CardBody, CardHeader} from "@nextui-org/card"; import Card from "@/app/(site)/components/Card"; import DreamModal from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/card/DreamModal"; @@ -13,8 +13,6 @@ import {deleteMutator, handleAxiosError} from "@/utils/client/client-utils"; type Props = { dream: Dream, isDisabled?: boolean, - allCharacters: DreamCharacter[], - allTags: DreamTag[], optimisticRemove?: OptimisticWorker, } @@ -22,7 +20,7 @@ const DeleteDream = (dreamId: string) => { return useSWRMutation(`/api/me/dreams/${dreamId}`, deleteMutator()) } -const DreamCard: FC = ({isDisabled, dream, allTags, allCharacters, optimisticRemove}) => { +const DreamCard: FC = ({isDisabled, dream, optimisticRemove}) => { const [modalOpen, setModalOpen] = useState(false) const {trigger: deleteDream} = DeleteDream(dream.id) @@ -36,8 +34,6 @@ const DreamCard: FC = ({isDisabled, dream, allTags, allCharacters, optimi setModalOpen(false)} onDelete={() => { diff --git a/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/card/DreamModal.tsx b/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/card/DreamModal.tsx index bbf9bb2..031e5ec 100644 --- a/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/card/DreamModal.tsx +++ b/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/card/DreamModal.tsx @@ -2,7 +2,7 @@ import {FC, Fragment, useState} from "react"; import Modal from "@/app/(site)/components/Modal"; -import {Dream, DreamCharacter, DreamTag} from "@prisma/client"; +import {Dream} from "@prisma/client"; import {Divider} from "@nextui-org/divider"; import {Button} from "@nextui-org/react"; import ConfirmationModal from "@/app/(site)/components/ConfirmationModal"; @@ -11,8 +11,6 @@ import DreamView from "@/app/(site)/(internal)/dashboard/(your-dreams)/component type Props = { dream: Dream, - allCharacters: DreamCharacter[], - allTags: DreamTag[], isOpen?: boolean, onClose?: () => void, onDelete?: () => void, @@ -20,7 +18,7 @@ type Props = { -const DreamModal: FC = ({dream, allTags, allCharacters, isOpen, onClose, onDelete}) => { +const DreamModal: FC = ({dream, isOpen, onClose, onDelete}) => { const [deleteModalOpen, setDeleteModalOpen] = useState(false) return ( @@ -41,8 +39,6 @@ const DreamModal: FC = ({dream, allTags, allCharacters, isOpen, onClose, > diff --git a/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/card/view/DreamView.tsx b/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/card/view/DreamView.tsx index 96f6826..1268e4b 100644 --- a/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/card/view/DreamView.tsx +++ b/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/card/view/DreamView.tsx @@ -1,7 +1,7 @@ "use client" import {FC, Fragment, useCallback, useEffect, useMemo, useState} from "react"; -import {Dream, DreamCharacter, DreamTag} from "@prisma/client"; +import {Dream} from "@prisma/client"; import {PatchDreamDto} from "@/app/api/me/dreams/dreams.dto"; import {calcEstimatedReadingTime, handleAxiosError,} from "@/utils/client/client-utils"; import {Chip} from "@nextui-org/chip"; @@ -14,17 +14,20 @@ import DreamEditableChip from "@/app/(site)/(internal)/dashboard/(your-dreams)/c import {DropdownItem, Spacer} from "@nextui-org/react"; import DreamEditableAddButton from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/card/view/DreamEditableAddButton"; -import {useDreamsData} from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/DreamsProvider"; +import { + useDreamsData, useUserDreamCharacters, + useUserDreamTags +} from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/DreamsProvider"; import {FetchFullDream, UpdateDream} from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/hooks/dream-api-utils"; type Props = { dream: Dream, - allCharacters: DreamCharacter[], - allTags: DreamTag[] fetchDream?: boolean, } -const DreamView: FC = ({dream, allTags, allCharacters, fetchDream}) => { +const DreamView: FC = ({dream, fetchDream}) => { + const {data: allTags} = useUserDreamTags() + const {data: allCharacters} = useUserDreamCharacters() const {data: fullDream, error: fullDreamError, mutate: mutateFullDream} = FetchFullDream(dream, fetchDream ?? true) const {trigger: updateDream} = UpdateDream(dream.id) const {dreams: {optimisticData: {editOptimisticData}}} = useDreamsData() diff --git a/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/containers/CurrentDreamsContainer.tsx b/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/containers/CurrentDreamsContainer.tsx index 4d3098f..4de9901 100644 --- a/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/containers/CurrentDreamsContainer.tsx +++ b/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/containers/CurrentDreamsContainer.tsx @@ -12,7 +12,7 @@ import {useTutorialsData} from "@/app/(site)/(internal)/dashboard/components/Tut const CurrentDreamsContainer: FC = () => { const [tutorialsState] = useTutorialsData() const [startOfToday, endOfToday] = useTodayTimeRange() - const {dreams, tags, characters} = useDreamsData() + const {dreams} = useDreamsData() const dreamCards = useMemo(() => dreams.data .filter(dream => { const creationDate = new Date(dream.createdAt.toString()); @@ -24,11 +24,9 @@ const CurrentDreamsContainer: FC = () => { isDisabled={!tutorialsState?.yourDreams} key={dream.id} dream={dream} - allTags={tags.data} - allCharacters={characters.data} optimisticRemove={dreams.optimisticData.removeOptimisticData} /> - )), [characters.data, dreams.data, dreams.optimisticData.removeOptimisticData, endOfToday, startOfToday, tags.data, tutorialsState?.yourDreams]) + )), [dreams.data, dreams.optimisticData.removeOptimisticData, endOfToday, startOfToday, tutorialsState?.yourDreams]) return ( { dateStyle: "medium" }) }`}> - + {dreams.loading ? ( diff --git a/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/containers/PastDreamItem.tsx b/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/containers/PastDreamItem.tsx index 965ea5a..6ba1a7c 100644 --- a/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/containers/PastDreamItem.tsx +++ b/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/containers/PastDreamItem.tsx @@ -10,20 +10,16 @@ import {DreamCharacter, DreamTag} from "@prisma/client"; type Props = { isDisabled?: boolean, dream: DayDreams, - allCharacters: DreamCharacter[], - allTags: DreamTag[], } -const PastDreamItem: FC = ({isDisabled, dream, allTags, allCharacters}) => { +const PastDreamItem: FC = ({isDisabled, dream}) => { const cards = useMemo(() => dream.dreams.map(pastDream => ( - )), [allCharacters, allTags, dream.dreams, isDisabled]) + )), [dream.dreams, isDisabled]) return ( diff --git a/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/containers/PastDreamsContainer.tsx b/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/containers/PastDreamsContainer.tsx index 659375e..3194b11 100644 --- a/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/containers/PastDreamsContainer.tsx +++ b/src/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/containers/PastDreamsContainer.tsx @@ -31,7 +31,7 @@ const NUMBER_OF_DAYS = 7 const PastDreamsContainer: FC = () => { const [tutorialsState] = useTutorialsData() const router = useRouter() - const {dreams, tags, characters} = useDreamsData() + const {dreams} = useDreamsData() const latestDate = useEndOfDay({ dayOffset: -1 }) @@ -49,10 +49,8 @@ const PastDreamsContainer: FC = () => { isDisabled={!tutorialsState?.yourDreams} key={dream.timestamp} dream={dream} - allTags={tags.data} - allCharacters={characters.data} /> - )), [characters.data, pastDreams, tags.data, tutorialsState?.yourDreams]) + )), [pastDreams, tutorialsState?.yourDreams]) return ( diff --git a/src/app/(site)/(internal)/dashboard/calendar/components/DreamCalendar.tsx b/src/app/(site)/(internal)/dashboard/calendar/components/DreamCalendar.tsx index b7a3f76..8a53df0 100644 --- a/src/app/(site)/(internal)/dashboard/calendar/components/DreamCalendar.tsx +++ b/src/app/(site)/(internal)/dashboard/calendar/components/DreamCalendar.tsx @@ -33,7 +33,7 @@ const DreamCalendar: FC = () => { ]; - const {dreams, tags, characters} = useDreamsData() + const {dreams} = useDreamsData() const dayDreams = useDayDreams({dreams: dreams.data}) const earliestYear = useMemo(() => dayDreams.length ? new Date(dayDreams[0].timestamp).getFullYear() : undefined, [dayDreams]) @@ -232,8 +232,6 @@ const DreamCalendar: FC = () => { , isToday: boolean, } -const DreamCalendarDay: FC = ({dreams, day, allTags, allCharacters, optimisticRemove, isToday}) => { +const DreamCalendarDay: FC = ({dreams, day, optimisticRemove, isToday}) => { const [modalOpen, setModalOpen] = useState(false) const dateStrSplit = day.dateString.split("-") @@ -47,8 +45,6 @@ const DreamCalendarDay: FC = ({dreams, day, allTags, allCharacters, optim ))} diff --git a/src/app/(site)/(internal)/dashboard/tags/components/GenericTagCard.tsx b/src/app/(site)/(internal)/dashboard/tags/components/GenericTagCard.tsx index 908d30c..6708387 100644 --- a/src/app/(site)/(internal)/dashboard/tags/components/GenericTagCard.tsx +++ b/src/app/(site)/(internal)/dashboard/tags/components/GenericTagCard.tsx @@ -9,11 +9,9 @@ import GenericTagModal from "@/app/(site)/(internal)/dashboard/tags/components/G type Props = { data: DreamCharacter | DreamTag, stateType: "tags" | "characters", - allCharacters: DreamCharacter[], - allTags: DreamTag[], } -const GenericTagCard: FC = ({data, stateType, allTags, allCharacters}) => { +const GenericTagCard: FC = ({data, stateType}) => { const [modalOpen, setModalOpen] = useState(false) return ( @@ -23,8 +21,6 @@ const GenericTagCard: FC = ({data, stateType, allTags, allCharacters}) => onClose={() => setModalOpen(false)} item={data} itemType={stateType} - allCharacters={allCharacters} - allTags={allTags} /> = ({state, stateType, allTags, allCharacters}) => { +const GenericTagContainer: FC = ({state, stateType}) => { const [tagSearch, setTagSearch] = useState() const [sortOrder, setSortOrder] = useState() const {paginatedData, totalPages, setCurrentPage} = usePagination(state.data, MAX_ITEMS_PER_PAGE) @@ -80,11 +78,9 @@ const GenericTagContainer: FC = ({state, stateType, allTags, allCharacter key={stateData.id} data={stateData} stateType={stateType} - allTags={allTags} - allCharacters={allCharacters} /> )) - ), [allCharacters, allTags, stateType, visibleData]) + ), [stateType, visibleData]) return ( diff --git a/src/app/(site)/(internal)/dashboard/tags/components/GenericTagDreamContainer.tsx b/src/app/(site)/(internal)/dashboard/tags/components/GenericTagDreamContainer.tsx index fe24bbc..da7989c 100644 --- a/src/app/(site)/(internal)/dashboard/tags/components/GenericTagDreamContainer.tsx +++ b/src/app/(site)/(internal)/dashboard/tags/components/GenericTagDreamContainer.tsx @@ -3,7 +3,6 @@ import {FC, Fragment, useMemo} from "react"; import DreamCard from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/card/DreamCard"; import {DreamWithRelations} from "@/app/api/me/dreams/dreams.dto"; -import {DreamCharacter, DreamTag} from "@prisma/client"; import DreamContainer from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/containers/DreamContainer"; import usePagination from "@/app/(site)/hooks/usePagination"; @@ -12,13 +11,11 @@ import Pagination from "@/app/(site)/components/Pagination"; type Props = { dreams?: DreamWithRelations[] | null - allCharacters: DreamCharacter[], - allTags: DreamTag[], } const MAX_ITEMS_PER_PAGE = 5 -const GenericTagDreamContainer: FC = ({dreams, allTags, allCharacters}) => { +const GenericTagDreamContainer: FC = ({dreams}) => { const {paginatedData, totalPages, setCurrentPage} = usePagination(dreams ?? [], MAX_ITEMS_PER_PAGE) const dreamCards = useMemo(() => { @@ -29,11 +26,9 @@ const GenericTagDreamContainer: FC = ({dreams, allTags, allCharacters}) = )) - }, [allCharacters, allTags, paginatedData]) + }, [paginatedData]) return ( diff --git a/src/app/(site)/(internal)/dashboard/tags/components/GenericTagModal.tsx b/src/app/(site)/(internal)/dashboard/tags/components/GenericTagModal.tsx index 6afa814..241e110 100644 --- a/src/app/(site)/(internal)/dashboard/tags/components/GenericTagModal.tsx +++ b/src/app/(site)/(internal)/dashboard/tags/components/GenericTagModal.tsx @@ -1,6 +1,6 @@ "use client" -import {FC, Fragment, useCallback, useMemo, useState} from "react"; +import {FC, Fragment, useCallback, useState} from "react"; import Modal from "@/app/(site)/components/Modal"; import {DreamCharacter, DreamTag} from "@prisma/client"; import {Divider} from "@nextui-org/divider"; @@ -21,8 +21,6 @@ type Props = { onClose?: () => void, item: DreamTag | DreamCharacter, itemType: "tags" | "characters", - allCharacters: DreamCharacter[], - allTags: DreamTag[], } const FetchDreams = (item: DreamTag | DreamCharacter, stateType: "tags" | "characters", isOpen?: boolean) => { @@ -32,10 +30,9 @@ const FetchDreams = (item: DreamTag | DreamCharacter, stateType: "tags" | "chara ) } -const GenericTagModal: FC = ({isOpen, onClose, item, itemType, allTags, allCharacters}) => { +const GenericTagModal: FC = ({isOpen, onClose, item, itemType}) => { const {data: dreams} = FetchDreams(item, itemType, isOpen) const [deleteModalOpen, setDeleteModalOpen] = useState(false) - const getItemName = useCallback(() => itemType === "tags" ? (item as DreamTag).tag : (item as DreamCharacter).name, [item, itemType]) return ( @@ -88,11 +85,7 @@ const GenericTagModal: FC = ({isOpen, onClose, item, itemType, allTags, a (dreams && dreams.length > 0) && ( - + ) diff --git a/src/app/(site)/(internal)/dashboard/tags/page.tsx b/src/app/(site)/(internal)/dashboard/tags/page.tsx index cbf8cf7..9a948fb 100644 --- a/src/app/(site)/(internal)/dashboard/tags/page.tsx +++ b/src/app/(site)/(internal)/dashboard/tags/page.tsx @@ -1,6 +1,6 @@ "use client" -import {FC, Fragment} from "react"; +import {FC} from "react"; import {useDreamsData} from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/DreamsProvider"; import GenericTagContainer from "@/app/(site)/(internal)/dashboard/tags/components/GenericTagContainer"; @@ -15,14 +15,10 @@ const TagsPage: FC = () => {