@edifice.io/react 2.6.12-develop-integration.20261103121816 → 2.6.12-develop-b2school.20261103172112
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Checkbox/Checkbox.js +1 -1
- package/dist/components/Dropdown/DropdownItem.js +17 -1
- package/dist/components/Layout/Layout.js +12 -4
- package/dist/components/Masonry/Masonry.d.ts +40 -0
- package/dist/components/Masonry/Masonry.js +50 -0
- package/dist/components/Masonry/index.d.ts +2 -0
- package/dist/components/SearchBar/SearchBar.js +17 -26
- package/dist/components/Tree/components/Tree.d.ts +2 -5
- package/dist/components/Tree/components/Tree.js +10 -7
- package/dist/components/Tree/hooks/useTree.d.ts +1 -0
- package/dist/components/Tree/hooks/useTree.js +6 -2
- package/dist/components/Tree/types/index.d.ts +7 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/homepage.js +97 -28
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/useDropdown/useDropdown.js +2 -2
- package/dist/hooks/useZendeskGuide/useZendeskGuide.d.ts +2 -6
- package/dist/hooks/useZendeskGuide/useZendeskGuide.js +11 -8
- package/dist/icons-apps.js +182 -184
- package/dist/icons.js +406 -404
- package/dist/index.js +194 -198
- package/dist/modules/HelpZone/HelpZone.js +6 -8
- package/dist/modules/HelpZone/HelpZoneContainer.js +2 -5
- package/dist/modules/editor/components/Editor/Editor.d.ts +5 -7
- package/dist/modules/editor/components/Editor/Editor.js +5 -3
- package/dist/modules/editor/components/EditorToolbar/EditorToolbar.d.ts +1 -3
- package/dist/modules/editor/components/EditorToolbar/EditorToolbar.js +8 -14
- package/dist/modules/editor/components/NodeView/ImageNodeView.d.ts +1 -1
- package/dist/modules/editor/components/NodeView/ImageNodeView.js +7 -14
- package/dist/modules/editor/hooks/useActionOptions.d.ts +1 -1
- package/dist/modules/editor/hooks/useActionOptions.js +12 -12
- package/dist/modules/editor/hooks/useTipTapEditor.d.ts +1 -2
- package/dist/modules/editor/hooks/useTipTapEditor.js +2 -2
- package/dist/modules/homepage/components/Agenda/Agenda.d.ts +10 -0
- package/dist/modules/homepage/components/Agenda/Agenda.js +54 -0
- package/dist/modules/homepage/components/Agenda/AgendaContainer.d.ts +1 -0
- package/dist/modules/homepage/components/Agenda/AgendaContainer.js +14 -0
- package/dist/modules/homepage/components/Agenda/AgendaEventCard.d.ts +10 -0
- package/dist/modules/homepage/components/Agenda/AgendaEventCard.js +30 -0
- package/dist/modules/homepage/components/Agenda/hooks/useAgendaContainer.d.ts +14 -0
- package/dist/modules/homepage/components/Agenda/hooks/useAgendaContainer.js +27 -0
- package/dist/modules/homepage/components/Agenda/index.d.ts +3 -0
- package/dist/modules/homepage/components/Agenda/services/api/agendaService.d.ts +24 -0
- package/dist/modules/homepage/components/Agenda/services/api/agendaService.js +45 -0
- package/dist/modules/homepage/components/Agenda/services/api/index.d.ts +4 -0
- package/dist/modules/homepage/components/Agenda/services/api/index.js +5 -0
- package/dist/modules/homepage/components/Agenda/services/queries/agenda.d.ts +19 -0
- package/dist/modules/homepage/components/Agenda/services/queries/agenda.js +26 -0
- package/dist/modules/homepage/components/BriefMe/BriefMe.d.ts +9 -0
- package/dist/modules/homepage/components/BriefMe/BriefMe.js +59 -0
- package/dist/modules/homepage/components/BriefMe/BriefMeContainer.d.ts +4 -0
- package/dist/modules/homepage/components/BriefMe/BriefMeContainer.js +17 -0
- package/dist/modules/homepage/components/BriefMe/index.d.ts +4 -0
- package/dist/modules/homepage/components/BriefMe/types.d.ts +17 -0
- package/dist/modules/homepage/components/BriefMe/types.js +8 -0
- package/dist/modules/homepage/components/BriefMe/useBriefMe.d.ts +31 -0
- package/dist/modules/homepage/components/BriefMe/useBriefMe.js +51 -0
- package/dist/modules/homepage/components/Cantine/Cantine.d.ts +7 -0
- package/dist/modules/homepage/components/Cantine/Cantine.js +44 -0
- package/dist/modules/homepage/components/Cantine/CantineContainer.d.ts +4 -0
- package/dist/modules/homepage/components/Cantine/CantineContainer.js +18 -0
- package/dist/modules/homepage/components/Cantine/CantineModal.d.ts +24 -0
- package/dist/modules/homepage/components/Cantine/CantineModal.js +88 -0
- package/dist/modules/homepage/components/Cantine/CantineModalContainer.d.ts +7 -0
- package/dist/modules/homepage/components/Cantine/CantineModalContainer.js +12 -0
- package/dist/modules/homepage/components/Cantine/components/CantineLegend.d.ts +5 -0
- package/dist/modules/homepage/components/Cantine/components/CantineLegend.js +22 -0
- package/dist/modules/homepage/components/Cantine/components/CantineMenuSection.d.ts +6 -0
- package/dist/modules/homepage/components/Cantine/components/CantineMenuSection.js +28 -0
- package/dist/modules/homepage/components/Cantine/components/cantineLabels.d.ts +12 -0
- package/dist/modules/homepage/components/Cantine/components/cantineLabels.js +60 -0
- package/dist/modules/homepage/components/Cantine/hooks/useCantine.d.ts +11 -0
- package/dist/modules/homepage/components/Cantine/hooks/useCantine.js +20 -0
- package/dist/modules/homepage/components/Cantine/hooks/useCantineMenu.d.ts +24 -0
- package/dist/modules/homepage/components/Cantine/hooks/useCantineMenu.js +65 -0
- package/dist/modules/homepage/components/Cantine/hooks/useCantineModal.d.ts +23 -0
- package/dist/modules/homepage/components/Cantine/hooks/useCantineModal.js +43 -0
- package/dist/modules/homepage/components/Cantine/index.d.ts +7 -0
- package/dist/modules/homepage/components/Cantine/types.d.ts +42 -0
- package/dist/modules/homepage/components/Edumalin/Edumalin.d.ts +9 -0
- package/dist/modules/homepage/components/Edumalin/Edumalin.js +65 -0
- package/dist/modules/homepage/components/Edumalin/EdumalinContainer.d.ts +4 -0
- package/dist/modules/homepage/components/Edumalin/EdumalinContainer.js +21 -0
- package/dist/modules/homepage/components/Edumalin/EdumalinModal.d.ts +8 -0
- package/dist/modules/homepage/components/Edumalin/EdumalinModal.js +62 -0
- package/dist/modules/homepage/components/Edumalin/components/EdumalinBadge.d.ts +5 -0
- package/dist/modules/homepage/components/Edumalin/components/EdumalinBadge.js +38 -0
- package/dist/modules/homepage/components/Edumalin/components/EdumalinPicture.d.ts +5 -0
- package/dist/modules/homepage/components/Edumalin/components/EdumalinPicture.js +12 -0
- package/dist/modules/homepage/components/Edumalin/index.d.ts +7 -0
- package/dist/modules/homepage/components/Edumalin/types.d.ts +24 -0
- package/dist/modules/homepage/components/Edumalin/types.js +4 -0
- package/dist/modules/homepage/components/Edumalin/useEdumalin.d.ts +16 -0
- package/dist/modules/homepage/components/Edumalin/useEdumalin.js +35 -0
- package/dist/modules/homepage/components/Edumalin/utils.d.ts +28 -0
- package/dist/modules/homepage/components/Edumalin/utils.js +56 -0
- package/dist/modules/homepage/components/GenerationHdf/GenerationHdf.d.ts +16 -0
- package/dist/modules/homepage/components/GenerationHdf/GenerationHdf.js +65 -0
- package/dist/modules/homepage/components/GenerationHdf/GenerationHdfContainer.d.ts +4 -0
- package/dist/modules/homepage/components/GenerationHdf/GenerationHdfContainer.js +12 -0
- package/dist/modules/homepage/components/GenerationHdf/formatSolde.d.ts +1 -0
- package/dist/modules/homepage/components/GenerationHdf/formatSolde.js +6 -0
- package/dist/modules/homepage/components/GenerationHdf/index.d.ts +3 -0
- package/dist/modules/homepage/components/GenerationHdf/useGenerationHdf.d.ts +10 -0
- package/dist/modules/homepage/components/GenerationHdf/useGenerationHdf.js +69 -0
- package/dist/modules/homepage/components/Header/Header.js +9 -21
- package/dist/modules/homepage/components/HomeCard/HomeCardHeader.d.ts +5 -1
- package/dist/modules/homepage/components/HomeCard/HomeCardHeader.js +1 -1
- package/dist/modules/homepage/components/Notifications/NotificationList.js +7 -8
- package/dist/modules/homepage/components/Notifications/NotificationListSkeleton.js +7 -12
- package/dist/modules/homepage/components/Notifications/NotificationSkeleton.js +7 -4
- package/dist/modules/homepage/components/Notifications/components/CommonNotificationItem.js +9 -9
- package/dist/modules/homepage/components/Notifications/components/NotificationFilterModal.js +11 -13
- package/dist/modules/homepage/components/Notifications/components/ReportNotificationModal.js +6 -12
- package/dist/modules/homepage/components/Notifications/components/notificationAdapter.d.ts +1 -2
- package/dist/modules/homepage/components/Notifications/components/notificationAdapter.js +14 -12
- package/dist/modules/homepage/components/Notifications/hooks/useNotificationList.js +9 -10
- package/dist/modules/homepage/components/Qwant/Qwant.d.ts +4 -0
- package/dist/modules/homepage/components/Qwant/Qwant.js +41 -0
- package/dist/modules/homepage/components/Qwant/QwantContainer.d.ts +1 -0
- package/dist/modules/homepage/components/Qwant/QwantContainer.js +10 -0
- package/dist/modules/homepage/components/Qwant/index.d.ts +3 -0
- package/dist/modules/homepage/components/Rss/Rss.d.ts +11 -0
- package/dist/modules/homepage/components/Rss/Rss.js +64 -0
- package/dist/modules/homepage/components/Rss/RssContainer.d.ts +1 -0
- package/dist/modules/homepage/components/Rss/RssContainer.js +45 -0
- package/dist/modules/homepage/components/Rss/RssFeedForm.d.ts +13 -0
- package/dist/modules/homepage/components/Rss/RssFeedForm.js +69 -0
- package/dist/modules/homepage/components/Rss/RssFeedsModal.d.ts +11 -0
- package/dist/modules/homepage/components/Rss/RssFeedsModal.js +58 -0
- package/dist/modules/homepage/components/Rss/hooks/useRssContainer.d.ts +25 -0
- package/dist/modules/homepage/components/Rss/hooks/useRssContainer.js +43 -0
- package/dist/modules/homepage/components/Rss/index.d.ts +6 -0
- package/dist/modules/homepage/components/Rss/services/api/index.d.ts +5 -0
- package/dist/modules/homepage/components/Rss/services/api/index.js +5 -0
- package/dist/modules/homepage/components/Rss/services/api/rssService.d.ts +38 -0
- package/dist/modules/homepage/components/Rss/services/api/rssService.js +51 -0
- package/dist/modules/homepage/components/Rss/services/queries/rss.d.ts +28 -0
- package/dist/modules/homepage/components/Rss/services/queries/rss.js +71 -0
- package/dist/modules/homepage/components/Rss/types.d.ts +25 -0
- package/dist/modules/homepage/components/Rss/utils.d.ts +7 -0
- package/dist/modules/homepage/components/Rss/utils.js +19 -0
- package/dist/modules/homepage/components/SchoolSpace/SchoolSpaceContainer.js +1 -1
- package/dist/modules/homepage/components/ScreenTime/ScreenTime.d.ts +11 -0
- package/dist/modules/homepage/components/ScreenTime/ScreenTime.js +49 -0
- package/dist/modules/homepage/components/ScreenTime/ScreenTimeChart.d.ts +10 -0
- package/dist/modules/homepage/components/ScreenTime/ScreenTimeChart.js +115 -0
- package/dist/modules/homepage/components/ScreenTime/ScreenTimeContainer.d.ts +1 -0
- package/dist/modules/homepage/components/ScreenTime/ScreenTimeContainer.js +25 -0
- package/dist/modules/homepage/components/ScreenTime/ScreenTimeError.d.ts +5 -0
- package/dist/modules/homepage/components/ScreenTime/ScreenTimeError.js +22 -0
- package/dist/modules/homepage/components/ScreenTime/ScreenTimeModal.d.ts +22 -0
- package/dist/modules/homepage/components/ScreenTime/ScreenTimeModal.js +81 -0
- package/dist/modules/homepage/components/ScreenTime/hooks/useScreenTimeContainer.d.ts +14 -0
- package/dist/modules/homepage/components/ScreenTime/hooks/useScreenTimeContainer.js +22 -0
- package/dist/modules/homepage/components/ScreenTime/hooks/useScreenTimeKids.d.ts +6 -0
- package/dist/modules/homepage/components/ScreenTime/hooks/useScreenTimeKids.js +25 -0
- package/dist/modules/homepage/components/ScreenTime/hooks/useScreenTimeModal.d.ts +31 -0
- package/dist/modules/homepage/components/ScreenTime/hooks/useScreenTimeModal.js +34 -0
- package/dist/modules/homepage/components/ScreenTime/index.d.ts +6 -0
- package/dist/modules/homepage/components/ScreenTime/services/api/index.d.ts +4 -0
- package/dist/modules/homepage/components/ScreenTime/services/api/index.js +5 -0
- package/dist/modules/homepage/components/ScreenTime/services/api/screenTimeService.d.ts +28 -0
- package/dist/modules/homepage/components/ScreenTime/services/api/screenTimeService.js +39 -0
- package/dist/modules/homepage/components/ScreenTime/services/queries/screenTime.d.ts +23 -0
- package/dist/modules/homepage/components/ScreenTime/services/queries/screenTime.js +41 -0
- package/dist/modules/homepage/components/ScreenTime/types.d.ts +30 -0
- package/dist/modules/homepage/components/ScreenTime/utils.d.ts +50 -0
- package/dist/modules/homepage/components/ScreenTime/utils.js +115 -0
- package/dist/modules/homepage/components/TabsKids/components/TabsKids.d.ts +43 -0
- package/dist/modules/homepage/components/TabsKids/components/TabsKids.js +23 -0
- package/dist/modules/homepage/components/TabsKids/components/TabsKidsItem.d.ts +34 -0
- package/dist/modules/homepage/components/TabsKids/components/TabsKidsItem.js +26 -0
- package/dist/modules/homepage/components/TabsKids/components/TabsKidsList.d.ts +14 -0
- package/dist/modules/homepage/components/TabsKids/components/TabsKidsList.js +64 -0
- package/dist/modules/homepage/components/TabsKids/hooks/useTabsKidsOverflow.d.ts +20 -0
- package/dist/modules/homepage/components/TabsKids/hooks/useTabsKidsOverflow.js +43 -0
- package/dist/modules/homepage/components/TabsKids/index.d.ts +3 -0
- package/dist/modules/homepage/components/TabsKids/utils/visibleTabs.d.ts +15 -0
- package/dist/modules/homepage/components/TabsKids/utils/visibleTabs.js +21 -0
- package/dist/modules/homepage/components/Universalis/Universalis.d.ts +8 -0
- package/dist/modules/homepage/components/Universalis/Universalis.js +62 -0
- package/dist/modules/homepage/components/Universalis/UniversalisContainer.d.ts +1 -0
- package/dist/modules/homepage/components/Universalis/UniversalisContainer.js +16 -0
- package/dist/modules/homepage/components/Universalis/index.d.ts +3 -0
- package/dist/modules/homepage/components/UsefulLinks/UsefulLinks.js +2 -2
- package/dist/modules/homepage/components/UsefulLinks/UsefulLinksModal.js +2 -2
- package/dist/modules/homepage/components/UserSpace/UserSpace.d.ts +3 -1
- package/dist/modules/homepage/components/UserSpace/UserSpace.js +13 -7
- package/dist/modules/homepage/components/UserSpace/UserSpaceContainer.d.ts +4 -2
- package/dist/modules/homepage/components/UserSpace/UserSpaceContainer.js +3 -2
- package/dist/modules/homepage/components/WidgetsPersonalizationPanel/WidgetToggle.d.ts +16 -0
- package/dist/modules/homepage/components/WidgetsPersonalizationPanel/WidgetToggle.js +15 -0
- package/dist/modules/homepage/components/WidgetsPersonalizationPanel/WidgetsPersonalizationPanel.d.ts +21 -0
- package/dist/modules/homepage/components/WidgetsPersonalizationPanel/WidgetsPersonalizationPanel.js +47 -0
- package/dist/modules/homepage/components/WidgetsPersonalizationPanel/index.d.ts +2 -0
- package/dist/modules/homepage/components/index.d.ts +12 -2
- package/dist/modules/homepage/{components/SchoolSpace → hooks}/useUserSchools.d.ts +2 -2
- package/dist/modules/homepage/{components/SchoolSpace → hooks}/useUserSchools.js +4 -4
- package/dist/modules/icons/components/IconAddWidget.d.ts +7 -0
- package/dist/modules/icons/components/IconAddWidget.js +12 -0
- package/dist/modules/icons/components/apps/index.d.ts +0 -1
- package/dist/modules/icons/components/index.d.ts +1 -0
- package/dist/modules/icons/components/nav/IconCommunitiesBeta.js +5 -7
- package/dist/modules/icons/components/nav/IconHomeBeta.js +6 -3
- package/dist/modules/icons/components/nav/IconMessagesBeta.js +7 -7
- package/dist/modules/icons/components/nav/IconMyAppsBeta.js +2 -3
- package/dist/modules/icons/components/nav/IconNotificationBeta.js +2 -4
- package/dist/modules/multimedia/FileCard/index.d.ts +0 -2
- package/dist/modules/multimedia/Linker/InternalLinker/InternalLinker.d.ts +1 -7
- package/dist/modules/multimedia/Linker/InternalLinker/InternalLinker.js +0 -2
- package/dist/modules/multimedia/MediaLibrary/MediaLibrary.js +5 -16
- package/dist/modules/multimedia/MediaLibrary/innertabs/index.d.ts +0 -1
- package/dist/modules/multimedia/MediaLibrary/innertabs/index.js +0 -2
- package/dist/modules/multimedia/Workspace/Workspace.js +1 -1
- package/dist/modules/multimedia/index.d.ts +0 -1
- package/dist/multimedia.js +22 -26
- package/package.json +7 -6
- package/dist/hooks/useGoogleDriveSearch/index.d.ts +0 -1
- package/dist/hooks/useGoogleDriveSearch/useGoogleDriveSearch.d.ts +0 -19
- package/dist/hooks/useGoogleDriveSearch/useGoogleDriveSearch.js +0 -60
- package/dist/modules/homepage/components/AlloLycee/AlloLycee.d.ts +0 -11
- package/dist/modules/homepage/components/AlloLycee/AlloLycee.js +0 -32
- package/dist/modules/homepage/components/AlloLycee/AlloLyceeContainer.d.ts +0 -4
- package/dist/modules/homepage/components/AlloLycee/AlloLyceeContainer.js +0 -10
- package/dist/modules/homepage/components/AlloLycee/index.d.ts +0 -3
- package/dist/modules/icons/components/apps/IconElea.d.ts +0 -7
- package/dist/modules/icons/components/apps/IconElea.js +0 -23
- package/dist/modules/multimedia/FileCard/GoogleDriveFileCard.d.ts +0 -25
- package/dist/modules/multimedia/FileCard/GoogleDriveFileCard.js +0 -102
- package/dist/modules/multimedia/GoogleDrive/GoogleDrive.d.ts +0 -24
- package/dist/modules/multimedia/GoogleDrive/GoogleDrive.js +0 -103
- package/dist/modules/multimedia/GoogleDrive/index.d.ts +0 -2
- package/dist/modules/multimedia/MediaLibrary/innertabs/GoogleDrive.d.ts +0 -1
- package/dist/modules/multimedia/MediaLibrary/innertabs/GoogleDrive.js +0 -61
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import clsx from "clsx";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { useTranslation } from "react-i18next";
|
|
5
|
+
import SvgIconFullScreen from "../../../icons/components/IconFullScreen.js";
|
|
6
|
+
import { ScreenTimeError } from "./ScreenTimeError.js";
|
|
7
|
+
import { formatDuration } from "./utils.js";
|
|
8
|
+
import TextSkeleton from "../../../../components/Skeleton/TextSkeleton.js";
|
|
9
|
+
import { TabsKids } from "../TabsKids/components/TabsKids.js";
|
|
10
|
+
import HomeCard from "../HomeCard/HomeCard.js";
|
|
11
|
+
import ButtonBeta from "../../../../components/ButtonBeta/ButtonBeta.js";
|
|
12
|
+
function ScreenTime({
|
|
13
|
+
status,
|
|
14
|
+
kids,
|
|
15
|
+
selectedKidId,
|
|
16
|
+
onKidChange,
|
|
17
|
+
todayMinutes,
|
|
18
|
+
yesterdayMinutes,
|
|
19
|
+
onFullScreenClick
|
|
20
|
+
}) {
|
|
21
|
+
const {
|
|
22
|
+
t
|
|
23
|
+
} = useTranslation(), tabs = useMemo(() => kids.map((kid) => ({
|
|
24
|
+
id: kid.id,
|
|
25
|
+
label: kid.firstName,
|
|
26
|
+
avatar: kid.avatarUrl
|
|
27
|
+
})), [kids]), card = /* @__PURE__ */ jsx("div", { className: clsx("screen-time__card", {
|
|
28
|
+
"screen-time__card--empty": status === "empty"
|
|
29
|
+
}), children: status === "empty" ? /* @__PURE__ */ jsx("p", { className: "screen-time__empty", children: t("homepage.widget.screenTime.empty") }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
30
|
+
/* @__PURE__ */ jsxs("div", { className: "screen-time__day", children: [
|
|
31
|
+
/* @__PURE__ */ jsx("span", { className: "screen-time__day-label", children: t("homepage.widget.screenTime.today") }),
|
|
32
|
+
status === "loading" ? /* @__PURE__ */ jsx(TextSkeleton, { size: "lg", className: "screen-time__day-skeleton" }) : /* @__PURE__ */ jsx("span", { className: "screen-time__day-value", children: formatDuration(todayMinutes) })
|
|
33
|
+
] }),
|
|
34
|
+
/* @__PURE__ */ jsxs("div", { className: "screen-time__day", children: [
|
|
35
|
+
/* @__PURE__ */ jsx("span", { className: "screen-time__day-label", children: t("homepage.widget.screenTime.yesterday") }),
|
|
36
|
+
status === "loading" ? /* @__PURE__ */ jsx(TextSkeleton, { size: "lg", className: "screen-time__day-skeleton" }) : /* @__PURE__ */ jsx("span", { className: "screen-time__day-value", children: formatDuration(yesterdayMinutes) })
|
|
37
|
+
] })
|
|
38
|
+
] }) }), content = kids.length > 0 ? /* @__PURE__ */ jsx(TabsKids, { items: tabs, activeId: selectedKidId ?? "", onChange: onKidChange, showTabBar: kids.length > 1, ariaLabel: t("homepage.widget.screenTime.kids"), children: card }) : card;
|
|
39
|
+
return /* @__PURE__ */ jsxs(HomeCard, { variant: "primary", className: "screen-time", children: [
|
|
40
|
+
/* @__PURE__ */ jsxs("div", { className: "screen-time__header", children: [
|
|
41
|
+
/* @__PURE__ */ jsx("h3", { className: "screen-time__title", children: t("homepage.widget.screenTime.title") }),
|
|
42
|
+
status !== "error" && /* @__PURE__ */ jsx(ButtonBeta, { "data-testid": "screen-time-button-fullscreen", "aria-label": t("homepage.widget.screenTime.open"), leftIcon: /* @__PURE__ */ jsx(SvgIconFullScreen, {}), variant: "ghost", color: "tertiary", onClick: onFullScreenClick })
|
|
43
|
+
] }),
|
|
44
|
+
/* @__PURE__ */ jsx(HomeCard.Content, { className: "screen-time__content", children: status === "error" ? /* @__PURE__ */ jsx(ScreenTimeError, { className: "screen-time__error" }) : content })
|
|
45
|
+
] });
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
ScreenTime
|
|
49
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ScreenTimeChartBar } from './types';
|
|
2
|
+
export interface ScreenTimeChartProps {
|
|
3
|
+
bars: ScreenTimeChartBar[];
|
|
4
|
+
axisMax: number;
|
|
5
|
+
axisStep: number;
|
|
6
|
+
labelStep: number;
|
|
7
|
+
axisTitle: string;
|
|
8
|
+
ariaLabel: string;
|
|
9
|
+
}
|
|
10
|
+
export default function ScreenTimeChart({ bars, axisMax, axisStep, labelStep, axisTitle, ariaLabel, }: ScreenTimeChartProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Chart, BarController, BarElement, CategoryScale, LinearScale, Tooltip } from "chart.js";
|
|
3
|
+
import { useRef, useEffect } from "react";
|
|
4
|
+
Chart.register(BarController, BarElement, CategoryScale, LinearScale, Tooltip);
|
|
5
|
+
function ScreenTimeChart({
|
|
6
|
+
bars,
|
|
7
|
+
axisMax,
|
|
8
|
+
axisStep,
|
|
9
|
+
labelStep,
|
|
10
|
+
axisTitle,
|
|
11
|
+
ariaLabel
|
|
12
|
+
}) {
|
|
13
|
+
const canvasRef = useRef(null), chartRef = useRef(), barsRef = useRef(bars);
|
|
14
|
+
return useEffect(() => {
|
|
15
|
+
const canvas = canvasRef.current;
|
|
16
|
+
if (!canvas) return;
|
|
17
|
+
const style = getComputedStyle(canvas), barColor = style.getPropertyValue("--primitive-blue-900").trim(), gridColor = style.getPropertyValue("--primitive-grey-300").trim(), textColor = style.getPropertyValue("--primitive-grey-900").trim(), fontFamily = style.getPropertyValue("--font-family-body").trim(), initialBars = barsRef.current, chart = new Chart(canvas, {
|
|
18
|
+
type: "bar",
|
|
19
|
+
data: {
|
|
20
|
+
labels: initialBars.map((bar) => bar.label),
|
|
21
|
+
datasets: [{
|
|
22
|
+
data: initialBars.map((bar) => bar.value),
|
|
23
|
+
backgroundColor: barColor,
|
|
24
|
+
borderRadius: 0,
|
|
25
|
+
categoryPercentage: 48 / 72
|
|
26
|
+
}]
|
|
27
|
+
},
|
|
28
|
+
options: {
|
|
29
|
+
responsive: !0,
|
|
30
|
+
maintainAspectRatio: !1,
|
|
31
|
+
plugins: {
|
|
32
|
+
legend: {
|
|
33
|
+
display: !1
|
|
34
|
+
},
|
|
35
|
+
tooltip: {
|
|
36
|
+
callbacks: {
|
|
37
|
+
label: (ctx) => {
|
|
38
|
+
var _a;
|
|
39
|
+
return ((_a = barsRef.current[ctx.dataIndex]) == null ? void 0 : _a.tooltip) ?? "";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
scales: {
|
|
45
|
+
y: {
|
|
46
|
+
min: 0,
|
|
47
|
+
max: axisMax,
|
|
48
|
+
ticks: {
|
|
49
|
+
stepSize: axisStep,
|
|
50
|
+
color: textColor,
|
|
51
|
+
font: {
|
|
52
|
+
family: fontFamily,
|
|
53
|
+
size: 16
|
|
54
|
+
},
|
|
55
|
+
callback: (value) => Number(value) % labelStep === 0 ? String(value) : ""
|
|
56
|
+
},
|
|
57
|
+
title: {
|
|
58
|
+
display: !0,
|
|
59
|
+
text: axisTitle,
|
|
60
|
+
color: textColor,
|
|
61
|
+
font: {
|
|
62
|
+
family: fontFamily,
|
|
63
|
+
size: 16
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
grid: {
|
|
67
|
+
color: gridColor
|
|
68
|
+
},
|
|
69
|
+
border: {
|
|
70
|
+
color: gridColor
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
x: {
|
|
74
|
+
grid: {
|
|
75
|
+
offset: !0,
|
|
76
|
+
color: gridColor
|
|
77
|
+
},
|
|
78
|
+
ticks: {
|
|
79
|
+
autoSkip: !1,
|
|
80
|
+
maxRotation: 0,
|
|
81
|
+
color: textColor,
|
|
82
|
+
font: {
|
|
83
|
+
family: fontFamily,
|
|
84
|
+
size: 16
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
border: {
|
|
88
|
+
color: gridColor
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
return chartRef.current = chart, () => {
|
|
95
|
+
chart.destroy(), chartRef.current = void 0;
|
|
96
|
+
};
|
|
97
|
+
}, []), useEffect(() => {
|
|
98
|
+
var _a;
|
|
99
|
+
const chart = chartRef.current;
|
|
100
|
+
if (!chart) return;
|
|
101
|
+
barsRef.current = bars, chart.data.labels = bars.map((bar) => bar.label), chart.data.datasets[0].data = bars.map((bar) => bar.value);
|
|
102
|
+
const yScale = (_a = chart.options.scales) == null ? void 0 : _a.y;
|
|
103
|
+
yScale && (yScale.max = axisMax, yScale.ticks && (yScale.ticks.stepSize = axisStep, yScale.ticks.callback = (value) => Number(value) % labelStep === 0 ? String(value) : ""), yScale.title && typeof yScale.title != "boolean" && (yScale.title.text = axisTitle)), chart.update();
|
|
104
|
+
}, [bars, axisMax, axisStep, labelStep, axisTitle]), /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
105
|
+
/* @__PURE__ */ jsx("canvas", { ref: canvasRef, role: "img", "aria-label": ariaLabel, className: "screen-time-modal__canvas" }),
|
|
106
|
+
/* @__PURE__ */ jsx("ul", { className: "visually-hidden", children: bars.map((bar, index) => /* @__PURE__ */ jsxs("li", { children: [
|
|
107
|
+
bar.srLabel,
|
|
108
|
+
": ",
|
|
109
|
+
bar.tooltip
|
|
110
|
+
] }, index)) })
|
|
111
|
+
] });
|
|
112
|
+
}
|
|
113
|
+
export {
|
|
114
|
+
ScreenTimeChart as default
|
|
115
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ScreenTimeContainer(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useScreenTimeContainer } from "./hooks/useScreenTimeContainer.js";
|
|
3
|
+
import { useScreenTimeModal } from "./hooks/useScreenTimeModal.js";
|
|
4
|
+
import { ScreenTime } from "./ScreenTime.js";
|
|
5
|
+
import { ScreenTimeModal } from "./ScreenTimeModal.js";
|
|
6
|
+
function ScreenTimeContainer() {
|
|
7
|
+
const {
|
|
8
|
+
kids,
|
|
9
|
+
selectedKid,
|
|
10
|
+
onKidChange,
|
|
11
|
+
todayMinutes,
|
|
12
|
+
yesterdayMinutes,
|
|
13
|
+
status
|
|
14
|
+
} = useScreenTimeContainer(), {
|
|
15
|
+
open: openModal,
|
|
16
|
+
...modal
|
|
17
|
+
} = useScreenTimeModal();
|
|
18
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
19
|
+
/* @__PURE__ */ jsx(ScreenTime, { status, kids, selectedKidId: selectedKid == null ? void 0 : selectedKid.id, onKidChange, todayMinutes, yesterdayMinutes, onFullScreenClick: () => openModal(selectedKid == null ? void 0 : selectedKid.id) }),
|
|
20
|
+
/* @__PURE__ */ jsx(ScreenTimeModal, { ...modal })
|
|
21
|
+
] });
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
ScreenTimeContainer
|
|
25
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import illuScreenTimeError from "@edifice.io/bootstrap/dist/images/homepage/illu-screen-time-error.svg";
|
|
3
|
+
import { useTranslation } from "react-i18next";
|
|
4
|
+
import Image from "../../../../components/Image/Image.js";
|
|
5
|
+
function ScreenTimeError({
|
|
6
|
+
className
|
|
7
|
+
}) {
|
|
8
|
+
const {
|
|
9
|
+
t
|
|
10
|
+
} = useTranslation();
|
|
11
|
+
return /* @__PURE__ */ jsxs("div", { className, children: [
|
|
12
|
+
/* @__PURE__ */ jsx(Image, { src: illuScreenTimeError, alt: "", className: "screen-time-error__illu" }),
|
|
13
|
+
/* @__PURE__ */ jsxs("p", { className: "screen-time-error__message", children: [
|
|
14
|
+
t("homepage.widget.screenTime.error.connection"),
|
|
15
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
16
|
+
t("homepage.widget.screenTime.error.contact")
|
|
17
|
+
] })
|
|
18
|
+
] });
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
ScreenTimeError
|
|
22
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ScreenTimeDayEntry, ScreenTimeHourEntry, ScreenTimeKid, ScreenTimeStatus, ScreenTimeView } from './types';
|
|
2
|
+
export interface ScreenTimeModalProps {
|
|
3
|
+
isOpen: boolean;
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
kids: ScreenTimeKid[];
|
|
6
|
+
selectedKid?: ScreenTimeKid;
|
|
7
|
+
onKidChange: (kidId: string) => void;
|
|
8
|
+
view: ScreenTimeView;
|
|
9
|
+
onViewChange: (view: ScreenTimeView) => void;
|
|
10
|
+
/** Displayed day ("YYYY-MM-DD"), or any day of the displayed week. */
|
|
11
|
+
date: string;
|
|
12
|
+
canGoPrevious: boolean;
|
|
13
|
+
canGoNext: boolean;
|
|
14
|
+
onPrevious: () => void;
|
|
15
|
+
onNext: () => void;
|
|
16
|
+
/** Weekly view data, once loaded. */
|
|
17
|
+
days?: ScreenTimeDayEntry[];
|
|
18
|
+
/** Daily view data, once loaded. */
|
|
19
|
+
hours?: ScreenTimeHourEntry[];
|
|
20
|
+
status: ScreenTimeStatus;
|
|
21
|
+
}
|
|
22
|
+
export declare function ScreenTimeModal({ isOpen, onClose, kids, selectedKid, onKidChange, view, onViewChange, date, canGoPrevious, canGoNext, onPrevious, onNext, days, hours, status, }: ScreenTimeModalProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, Suspense, lazy } from "react";
|
|
3
|
+
import { useTranslation } from "react-i18next";
|
|
4
|
+
import SvgIconRafterLeft from "../../../icons/components/IconRafterLeft.js";
|
|
5
|
+
import SvgIconRafterRight from "../../../icons/components/IconRafterRight.js";
|
|
6
|
+
import { ScreenTimeError } from "./ScreenTimeError.js";
|
|
7
|
+
import { getWeekBounds, buildWeeklyBars, buildDailyBars, getAxisMax, SCREEN_TIME_LEARN_MORE_URL, SCREEN_TIME_AXIS, getAxisLabelStep } from "./utils.js";
|
|
8
|
+
import useDate from "../../../../hooks/useDate/useDate.js";
|
|
9
|
+
import ModalBeta from "../../../../components/ModalBeta/ModalBeta.js";
|
|
10
|
+
import Alert from "../../../../components/Alert/Alert.js";
|
|
11
|
+
import ButtonBeta from "../../../../components/ButtonBeta/ButtonBeta.js";
|
|
12
|
+
import Select from "../../../../components/Select/Select.js";
|
|
13
|
+
import SegmentedControl from "../../../../components/SegmentedControl/SegmentedControl.js";
|
|
14
|
+
import Loading from "../../../../components/Loading/Loading.js";
|
|
15
|
+
const ScreenTimeChart = /* @__PURE__ */ lazy(() => import("./ScreenTimeChart.js"));
|
|
16
|
+
function ScreenTimeModal({
|
|
17
|
+
isOpen,
|
|
18
|
+
onClose,
|
|
19
|
+
kids,
|
|
20
|
+
selectedKid,
|
|
21
|
+
onKidChange,
|
|
22
|
+
view,
|
|
23
|
+
onViewChange,
|
|
24
|
+
date,
|
|
25
|
+
canGoPrevious,
|
|
26
|
+
canGoNext,
|
|
27
|
+
onPrevious,
|
|
28
|
+
onNext,
|
|
29
|
+
days,
|
|
30
|
+
hours,
|
|
31
|
+
status
|
|
32
|
+
}) {
|
|
33
|
+
const {
|
|
34
|
+
t
|
|
35
|
+
} = useTranslation(), {
|
|
36
|
+
formatDate
|
|
37
|
+
} = useDate(), week = getWeekBounds(date), bars = useMemo(() => view === "weekly" ? buildWeeklyBars(week.start, days ?? [], formatDate) : buildDailyBars(hours ?? []), [view, week.start, days, hours, formatDate]), axisMax = getAxisMax(view, bars.map((bar) => bar.value)), periodLabel = view === "weekly" ? t("homepage.widget.screenTime.modal.week", {
|
|
38
|
+
start: formatDate(week.start, "D MMMM"),
|
|
39
|
+
end: formatDate(week.end, "D MMMM")
|
|
40
|
+
}) : t("homepage.widget.screenTime.modal.day", {
|
|
41
|
+
date: formatDate(date, "dddd D MMMM")
|
|
42
|
+
});
|
|
43
|
+
return /* @__PURE__ */ jsxs(ModalBeta, { id: "screen-time-modal", size: "l", isOpen, onModalClose: onClose, children: [
|
|
44
|
+
/* @__PURE__ */ jsx(ModalBeta.Header, { onModalClose: onClose, children: t("homepage.widget.screenTime.title") }),
|
|
45
|
+
/* @__PURE__ */ jsxs(ModalBeta.Body, { className: "screen-time-modal", children: [
|
|
46
|
+
/* @__PURE__ */ jsx(Alert, { type: "info", isDismissible: !0, button: /* @__PURE__ */ jsx(ButtonBeta, { "data-testid": "screen-time-modal-button-learn-more", variant: "ghost", onClick: () => window.open(SCREEN_TIME_LEARN_MORE_URL, "_blank", "noopener,noreferrer"), children: t("homepage.widget.screenTime.modal.learnMore") }), children: t("homepage.widget.screenTime.modal.info") }),
|
|
47
|
+
/* @__PURE__ */ jsxs("div", { className: "screen-time-modal__toolbar", children: [
|
|
48
|
+
kids.length > 1 && /* @__PURE__ */ jsxs("div", { className: "screen-time-modal__kid", children: [
|
|
49
|
+
/* @__PURE__ */ jsx("span", { className: "screen-time-modal__kid-label", children: t("homepage.widget.screenTime.modal.student") }),
|
|
50
|
+
/* @__PURE__ */ jsx("div", { "data-testid": "screen-time-modal-input-kid", children: /* @__PURE__ */ jsx(Select, { placeholderOption: (selectedKid == null ? void 0 : selectedKid.displayName) ?? "", options: kids.map((kid) => ({
|
|
51
|
+
value: kid.id,
|
|
52
|
+
label: kid.displayName
|
|
53
|
+
})), selectedValue: selectedKid && {
|
|
54
|
+
value: selectedKid.id,
|
|
55
|
+
label: selectedKid.displayName
|
|
56
|
+
}, onValueChange: (option) => onKidChange(typeof option == "string" ? option : option.value) }) })
|
|
57
|
+
] }),
|
|
58
|
+
/* @__PURE__ */ jsx(SegmentedControl, { "data-testid": "screen-time-modal-input-view", options: [{
|
|
59
|
+
value: "weekly",
|
|
60
|
+
label: t("homepage.widget.screenTime.modal.weekly")
|
|
61
|
+
}, {
|
|
62
|
+
value: "daily",
|
|
63
|
+
label: t("homepage.widget.screenTime.modal.daily")
|
|
64
|
+
}], value: view, onChange: (value) => onViewChange(value), className: "screen-time-modal__view" })
|
|
65
|
+
] }),
|
|
66
|
+
/* @__PURE__ */ jsxs("div", { className: "screen-time-modal__nav", children: [
|
|
67
|
+
/* @__PURE__ */ jsx(ButtonBeta, { "data-testid": "screen-time-modal-button-previous", "aria-label": t("homepage.widget.screenTime.modal.previous"), leftIcon: /* @__PURE__ */ jsx(SvgIconRafterLeft, {}), variant: "ghost", disabled: !canGoPrevious, onClick: onPrevious }),
|
|
68
|
+
/* @__PURE__ */ jsx("p", { className: "screen-time-modal__period", children: periodLabel }),
|
|
69
|
+
/* @__PURE__ */ jsx(ButtonBeta, { "data-testid": "screen-time-modal-button-next", "aria-label": t("homepage.widget.screenTime.modal.next"), leftIcon: /* @__PURE__ */ jsx(SvgIconRafterRight, {}), variant: "ghost", disabled: !canGoNext, onClick: onNext })
|
|
70
|
+
] }),
|
|
71
|
+
status === "error" ? /* @__PURE__ */ jsx(ScreenTimeError, { className: "screen-time-modal__error" }) : /* @__PURE__ */ jsxs("div", { className: "screen-time-modal__chart", children: [
|
|
72
|
+
/* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx("div", { className: "screen-time-modal__chart-placeholder" }), children: /* @__PURE__ */ jsx(ScreenTimeChart, { bars, axisMax, axisStep: SCREEN_TIME_AXIS[view].step, labelStep: getAxisLabelStep(view, axisMax), axisTitle: t(view === "weekly" ? "homepage.widget.screenTime.modal.hours" : "homepage.widget.screenTime.modal.minutes"), ariaLabel: periodLabel }) }),
|
|
73
|
+
status === "loading" && /* @__PURE__ */ jsx("div", { className: "screen-time-modal__chart-overlay", children: /* @__PURE__ */ jsx(Loading, { isLoading: !0 }) }),
|
|
74
|
+
status === "empty" && /* @__PURE__ */ jsx("div", { className: "screen-time-modal__chart-overlay", children: /* @__PURE__ */ jsx("span", { className: "screen-time-modal__no-data", children: t("homepage.widget.screenTime.modal.noData") }) })
|
|
75
|
+
] })
|
|
76
|
+
] })
|
|
77
|
+
] });
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
ScreenTimeModal
|
|
81
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ScreenTimeKid, ScreenTimeStatus } from '../types';
|
|
2
|
+
export interface UseScreenTimeContainerReturn {
|
|
3
|
+
kids: ScreenTimeKid[];
|
|
4
|
+
selectedKid?: ScreenTimeKid;
|
|
5
|
+
onKidChange: (kidId: string) => void;
|
|
6
|
+
todayMinutes: number;
|
|
7
|
+
yesterdayMinutes: number;
|
|
8
|
+
status: ScreenTimeStatus;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Custom hook that provides today's and yesterday's total screen time of the
|
|
12
|
+
* selected kid.
|
|
13
|
+
*/
|
|
14
|
+
export declare const useScreenTimeContainer: () => UseScreenTimeContainerReturn;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { useEdificeClient } from "../../../../../providers/EdificeClientProvider/EdificeClientProvider.hook.js";
|
|
3
|
+
import { useDailyScreenTime } from "../services/queries/screenTime.js";
|
|
4
|
+
import { getToday, addDays, getScreenTimeStatus, sumMinutes } from "../utils.js";
|
|
5
|
+
import { useScreenTimeKids } from "./useScreenTimeKids.js";
|
|
6
|
+
const useScreenTimeContainer = () => {
|
|
7
|
+
const kids = useScreenTimeKids(), {
|
|
8
|
+
sessionQuery
|
|
9
|
+
} = useEdificeClient(), [selectedKidId, setSelectedKidId] = useState(), selectedKid = kids.find((kid) => kid.id === selectedKidId) ?? kids[0], today = getToday(), yesterday = addDays(today, -1), todayQuery = useDailyScreenTime(selectedKid == null ? void 0 : selectedKid.id, today), yesterdayQuery = useDailyScreenTime(selectedKid == null ? void 0 : selectedKid.id, yesterday);
|
|
10
|
+
let status = getScreenTimeStatus([todayQuery, yesterdayQuery]);
|
|
11
|
+
return selectedKid || (status = sessionQuery.isError ? "error" : "loading"), {
|
|
12
|
+
kids,
|
|
13
|
+
selectedKid,
|
|
14
|
+
onKidChange: setSelectedKidId,
|
|
15
|
+
todayMinutes: sumMinutes(todayQuery.data ?? []),
|
|
16
|
+
yesterdayMinutes: sumMinutes(yesterdayQuery.data ?? []),
|
|
17
|
+
status
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
useScreenTimeContainer
|
|
22
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { odeServices } from "@edifice.io/client";
|
|
3
|
+
import useUser from "../../../../../hooks/useUser/useUser.js";
|
|
4
|
+
function useScreenTimeKids() {
|
|
5
|
+
const {
|
|
6
|
+
user
|
|
7
|
+
} = useUser();
|
|
8
|
+
return useMemo(() => {
|
|
9
|
+
if (!user) return [];
|
|
10
|
+
const children = user.children, people = Object.entries(children ?? {});
|
|
11
|
+
return people.length === 0 && people.push([user.userId, user]), people.map(([id, {
|
|
12
|
+
firstName,
|
|
13
|
+
lastName
|
|
14
|
+
}]) => ({
|
|
15
|
+
id,
|
|
16
|
+
firstName,
|
|
17
|
+
lastName,
|
|
18
|
+
displayName: `${firstName} ${lastName}`,
|
|
19
|
+
avatarUrl: odeServices.directory().getAvatarUrl(id, "user")
|
|
20
|
+
}));
|
|
21
|
+
}, [user]);
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
useScreenTimeKids
|
|
25
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ScreenTimeDayEntry, ScreenTimeHourEntry, ScreenTimeKid, ScreenTimeStatus, ScreenTimeView } from '../types';
|
|
2
|
+
export interface UseScreenTimeModalReturn {
|
|
3
|
+
isOpen: boolean;
|
|
4
|
+
/** Opens the modal on today's week, for the given kid. */
|
|
5
|
+
open: (kidId?: string) => void;
|
|
6
|
+
onClose: () => void;
|
|
7
|
+
kids: ScreenTimeKid[];
|
|
8
|
+
selectedKid?: ScreenTimeKid;
|
|
9
|
+
onKidChange: (kidId: string) => void;
|
|
10
|
+
view: ScreenTimeView;
|
|
11
|
+
onViewChange: (view: ScreenTimeView) => void;
|
|
12
|
+
/** Displayed day ("YYYY-MM-DD"), or any day of the displayed week. */
|
|
13
|
+
date: string;
|
|
14
|
+
canGoPrevious: boolean;
|
|
15
|
+
canGoNext: boolean;
|
|
16
|
+
onPrevious: () => void;
|
|
17
|
+
onNext: () => void;
|
|
18
|
+
/** Weekly view data, once loaded. */
|
|
19
|
+
days?: ScreenTimeDayEntry[];
|
|
20
|
+
/** Daily view data, once loaded. */
|
|
21
|
+
hours?: ScreenTimeHourEntry[];
|
|
22
|
+
status: ScreenTimeStatus;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Custom hook that provides the state of the full-screen modal: which kid,
|
|
26
|
+
* view and period are displayed, and their screen time.
|
|
27
|
+
*
|
|
28
|
+
* The kid picked here stays local to the modal on purpose: it must not
|
|
29
|
+
* change the widget's own selected kid.
|
|
30
|
+
*/
|
|
31
|
+
export declare const useScreenTimeModal: () => UseScreenTimeModalReturn;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { useWeeklyScreenTime, useDailyScreenTime } from "../services/queries/screenTime.js";
|
|
3
|
+
import { getToday, getWeekBounds, getPreviousPeriodDate, getNextPeriodDate, getScreenTimeStatus } from "../utils.js";
|
|
4
|
+
import { useScreenTimeKids } from "./useScreenTimeKids.js";
|
|
5
|
+
const useScreenTimeModal = () => {
|
|
6
|
+
const kids = useScreenTimeKids(), [isOpen, setIsOpen] = useState(!1), [kidId, setKidId] = useState(), [view, setView] = useState("weekly"), [date, setDate] = useState(getToday), selectedKid = kids.find((kid) => kid.id === kidId) ?? kids[0], week = getWeekBounds(date), weeklyQuery = useWeeklyScreenTime(selectedKid == null ? void 0 : selectedKid.id, week.start, week.end, {
|
|
7
|
+
enabled: isOpen && view === "weekly"
|
|
8
|
+
}), dailyQuery = useDailyScreenTime(selectedKid == null ? void 0 : selectedKid.id, date, {
|
|
9
|
+
enabled: isOpen && view === "daily"
|
|
10
|
+
}), open = (initialKidId) => {
|
|
11
|
+
setKidId(initialKidId), setView("weekly"), setDate(getToday()), setIsOpen(!0);
|
|
12
|
+
}, today = getToday(), previousDate = getPreviousPeriodDate(view, date, today), nextDate = getNextPeriodDate(view, date, today);
|
|
13
|
+
return {
|
|
14
|
+
isOpen,
|
|
15
|
+
open,
|
|
16
|
+
onClose: () => setIsOpen(!1),
|
|
17
|
+
kids,
|
|
18
|
+
selectedKid,
|
|
19
|
+
onKidChange: setKidId,
|
|
20
|
+
view,
|
|
21
|
+
onViewChange: setView,
|
|
22
|
+
date,
|
|
23
|
+
canGoPrevious: previousDate !== void 0,
|
|
24
|
+
canGoNext: nextDate !== void 0,
|
|
25
|
+
onPrevious: () => previousDate && setDate(previousDate),
|
|
26
|
+
onNext: () => nextDate && setDate(nextDate),
|
|
27
|
+
days: weeklyQuery.data,
|
|
28
|
+
hours: dailyQuery.data,
|
|
29
|
+
status: getScreenTimeStatus([view === "weekly" ? weeklyQuery : dailyQuery])
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
useScreenTimeModal
|
|
34
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ScreenTimeDayEntry, ScreenTimeHourEntry } from '../../types';
|
|
2
|
+
export declare class ScreenTimeRequestError extends Error {
|
|
3
|
+
readonly status: number;
|
|
4
|
+
constructor(status: number);
|
|
5
|
+
}
|
|
6
|
+
/** A 404 means "no data for this kid upstream", not a failure. */
|
|
7
|
+
export declare const isNotFoundError: (error: unknown) => boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Creates the service of the homepage "Screen time" widget.
|
|
10
|
+
*
|
|
11
|
+
* Backend contract:
|
|
12
|
+
* - `GET /appregistry/screen-time/:kidId/daily?date=…` returns
|
|
13
|
+
* `{ durations }`, one entry per hour.
|
|
14
|
+
* - `GET /appregistry/screen-time/:kidId/weekly?startDate=…&endDate=…`
|
|
15
|
+
* returns `{ dailySummaries }`, one entry per day.
|
|
16
|
+
*
|
|
17
|
+
* @param baseURL The base URL for the screen-time service API.
|
|
18
|
+
*/
|
|
19
|
+
export declare const createScreenTimeService: (baseURL: string) => {
|
|
20
|
+
/**
|
|
21
|
+
* Get a kid's screen time for each hour of a day.
|
|
22
|
+
*/
|
|
23
|
+
getDaily(kidId: string, date: string): Promise<ScreenTimeHourEntry[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Get a kid's screen time for each day between two dates.
|
|
26
|
+
*/
|
|
27
|
+
getWeekly(kidId: string, startDate: string, endDate: string): Promise<ScreenTimeDayEntry[]>;
|
|
28
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { odeServices } from "@edifice.io/client";
|
|
2
|
+
class ScreenTimeRequestError extends Error {
|
|
3
|
+
constructor(status) {
|
|
4
|
+
super(`screen-time ${status}`), this.status = status;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
const isNotFoundError = (error) => error instanceof ScreenTimeRequestError && error.status === 404, createScreenTimeService = (baseURL) => {
|
|
8
|
+
async function get(path) {
|
|
9
|
+
const http = odeServices.http();
|
|
10
|
+
try {
|
|
11
|
+
return await http.get(`${baseURL}/appregistry/screen-time/${path}`, {
|
|
12
|
+
disableNotifications: !0
|
|
13
|
+
});
|
|
14
|
+
} catch {
|
|
15
|
+
throw new ScreenTimeRequestError(http.latestResponse.status);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
/**
|
|
20
|
+
* Get a kid's screen time for each hour of a day.
|
|
21
|
+
*/
|
|
22
|
+
async getDaily(kidId, date) {
|
|
23
|
+
const body = await get(`${encodeURIComponent(kidId)}/daily?date=${date}`);
|
|
24
|
+
return Array.isArray(body == null ? void 0 : body.durations) ? body.durations : [];
|
|
25
|
+
},
|
|
26
|
+
/**
|
|
27
|
+
* Get a kid's screen time for each day between two dates.
|
|
28
|
+
*/
|
|
29
|
+
async getWeekly(kidId, startDate, endDate) {
|
|
30
|
+
const body = await get(`${encodeURIComponent(kidId)}/weekly?startDate=${startDate}&endDate=${endDate}`);
|
|
31
|
+
return Array.isArray(body == null ? void 0 : body.dailySummaries) ? body.dailySummaries : [];
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export {
|
|
36
|
+
ScreenTimeRequestError,
|
|
37
|
+
createScreenTimeService,
|
|
38
|
+
isNotFoundError
|
|
39
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const screenTimeQueryKeys: {
|
|
2
|
+
all: () => readonly ["screen-time"];
|
|
3
|
+
daily: (kidId: string, date: string) => readonly ["screen-time", "daily", string, string];
|
|
4
|
+
weekly: (kidId: string, startDate: string, endDate: string) => readonly ["screen-time", "weekly", string, string, string];
|
|
5
|
+
};
|
|
6
|
+
export declare const screenTimeQueryOptions: {
|
|
7
|
+
getDaily(kidId: string, date: string): import('@tanstack/react-query').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<import('../..').ScreenTimeHourEntry[], Error, import('../..').ScreenTimeHourEntry[], import('@tanstack/react-query').QueryKey>, "queryFn"> & {
|
|
8
|
+
queryFn?: import('@tanstack/react-query').QueryFunction<import('../..').ScreenTimeHourEntry[], import('@tanstack/react-query').QueryKey, never> | undefined;
|
|
9
|
+
} & {
|
|
10
|
+
queryKey: import('@tanstack/react-query').DataTag<import('@tanstack/react-query').QueryKey, import('../..').ScreenTimeHourEntry[]>;
|
|
11
|
+
};
|
|
12
|
+
getWeekly(kidId: string, startDate: string, endDate: string): import('@tanstack/react-query').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<import('../..').ScreenTimeDayEntry[], Error, import('../..').ScreenTimeDayEntry[], import('@tanstack/react-query').QueryKey>, "queryFn"> & {
|
|
13
|
+
queryFn?: import('@tanstack/react-query').QueryFunction<import('../..').ScreenTimeDayEntry[], import('@tanstack/react-query').QueryKey, never> | undefined;
|
|
14
|
+
} & {
|
|
15
|
+
queryKey: import('@tanstack/react-query').DataTag<import('@tanstack/react-query').QueryKey, import('../..').ScreenTimeDayEntry[]>;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare const useDailyScreenTime: (kidId: string | undefined, date: string, { enabled }?: {
|
|
19
|
+
enabled?: boolean | undefined;
|
|
20
|
+
}) => import('@tanstack/react-query').UseQueryResult<import('../..').ScreenTimeHourEntry[], Error>;
|
|
21
|
+
export declare const useWeeklyScreenTime: (kidId: string | undefined, startDate: string, endDate: string, { enabled }?: {
|
|
22
|
+
enabled?: boolean | undefined;
|
|
23
|
+
}) => import('@tanstack/react-query').UseQueryResult<import('../..').ScreenTimeDayEntry[], Error>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useQuery, queryOptions } from "@tanstack/react-query";
|
|
2
|
+
import { screenTimeService } from "../api/index.js";
|
|
3
|
+
import { isNotFoundError } from "../api/screenTimeService.js";
|
|
4
|
+
const STALE_TIME = 5 * 60 * 1e3, retryUnlessNotFound = (failureCount, error) => !isNotFoundError(error) && failureCount < 3, screenTimeQueryKeys = {
|
|
5
|
+
all: () => ["screen-time"],
|
|
6
|
+
daily: (kidId, date) => [...screenTimeQueryKeys.all(), "daily", kidId, date],
|
|
7
|
+
weekly: (kidId, startDate, endDate) => [...screenTimeQueryKeys.all(), "weekly", kidId, startDate, endDate]
|
|
8
|
+
}, screenTimeQueryOptions = {
|
|
9
|
+
getDaily(kidId, date) {
|
|
10
|
+
return queryOptions({
|
|
11
|
+
queryKey: screenTimeQueryKeys.daily(kidId, date),
|
|
12
|
+
queryFn: () => screenTimeService.getDaily(kidId, date),
|
|
13
|
+
staleTime: STALE_TIME,
|
|
14
|
+
retry: retryUnlessNotFound
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
getWeekly(kidId, startDate, endDate) {
|
|
18
|
+
return queryOptions({
|
|
19
|
+
queryKey: screenTimeQueryKeys.weekly(kidId, startDate, endDate),
|
|
20
|
+
queryFn: () => screenTimeService.getWeekly(kidId, startDate, endDate),
|
|
21
|
+
staleTime: STALE_TIME,
|
|
22
|
+
retry: retryUnlessNotFound
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}, useDailyScreenTime = (kidId, date, {
|
|
26
|
+
enabled = !0
|
|
27
|
+
} = {}) => useQuery({
|
|
28
|
+
...screenTimeQueryOptions.getDaily(kidId ?? "", date),
|
|
29
|
+
enabled: enabled && !!kidId
|
|
30
|
+
}), useWeeklyScreenTime = (kidId, startDate, endDate, {
|
|
31
|
+
enabled = !0
|
|
32
|
+
} = {}) => useQuery({
|
|
33
|
+
...screenTimeQueryOptions.getWeekly(kidId ?? "", startDate, endDate),
|
|
34
|
+
enabled: enabled && !!kidId
|
|
35
|
+
});
|
|
36
|
+
export {
|
|
37
|
+
screenTimeQueryKeys,
|
|
38
|
+
screenTimeQueryOptions,
|
|
39
|
+
useDailyScreenTime,
|
|
40
|
+
useWeeklyScreenTime
|
|
41
|
+
};
|