Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 62 additions & 31 deletions src/components/Learn/TipOfTheDay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,81 @@ import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Icon } from "@/components/ui/icon";
import { BlockStack, InlineStack } from "@/components/ui/layout";
import { Heading, Paragraph } from "@/components/ui/typography";
import { Heading, Text } from "@/components/ui/typography";
import { tracking } from "@/utils/tracking";

const STUB_TIP = {
id: "subgraph-navigation",
category: "Editor",
title: "Use subgraphs to keep complex pipelines readable",
body: "Double-click any task to dive into its subgraph. Use the breadcrumbs at the top of the editor to navigate back up — perfect for organising large pipelines without clutter.",
};
import { tips } from "./tips";

function getDayOfYear(date: Date) {
const start = Date.UTC(date.getUTCFullYear(), 0, 0);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 getDayOfYear uses UTC date methods (getUTCFullYear, getUTCMonth, getUTCDate), so the tip rotates at UTC midnight rather than the user's local midnight. A user in UTC+10 sees the tip change at 10am their time. Use the local equivalents (getFullYear(), getMonth(), getDate()) to match the user's calendar day.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I considered localizing this to the user but I also kind of like that most people will see multiple tips in a day??


const now = Date.UTC(
date.getUTCFullYear(),
date.getUTCMonth(),
date.getUTCDate(),
);

return Math.floor((now - start) / 86_400_000);
}

interface TipOfTheDayProps {
variant?: "card" | "compact";
}

export function TipOfTheDay({ variant = "card" }: TipOfTheDayProps = {}) {
const index = getDayOfYear(new Date()) % tips.length;
const tip = tips[index];
const isCompact = variant === "compact";
const textSize = isCompact ? "xs" : "sm";

const badge = (
<Badge size="sm" variant="secondary">
{tip.category}
</Badge>
);

export function TipOfTheDay() {
return (
<div className="h-full rounded-xl border border-border bg-card p-5">
<BlockStack gap="3" className="h-full">
<InlineStack gap="2" blockAlign="center" align="space-between">
<InlineStack gap="2" blockAlign="center">
<Icon
name="Lightbulb"
size="md"
className="text-amber-500"
aria-hidden="true"
/>
<Heading level={3}>Tip of the day</Heading>
<div
className={
isCompact
? "h-full p-2"
: "h-full rounded-xl border border-border bg-card p-5"
}
>
<BlockStack gap={isCompact ? "2" : "3"} className="h-full">
{!isCompact && (
<InlineStack gap="2" blockAlign="center" align="space-between">
<InlineStack gap="2" blockAlign="center">
<Icon
name="Lightbulb"
size="md"
className="text-amber-500"
aria-hidden="true"
/>
<Heading level={3}>Tip of the day</Heading>
</InlineStack>
{badge}
</InlineStack>
<Badge size="sm" variant="secondary">
{STUB_TIP.category}
</Badge>
</InlineStack>
)}

<BlockStack gap="1" className="flex-1">
<Paragraph size="sm" weight="semibold">
{STUB_TIP.title}
</Paragraph>
<Paragraph size="sm" tone="subdued">
{STUB_TIP.body}
</Paragraph>
<InlineStack gap="2" blockAlign="center" align="space-between">
<Text as="p" size={textSize} weight="semibold">
{tip.title}
</Text>
{isCompact && badge}
</InlineStack>
<Text as="p" size={textSize} tone="subdued">
{tip.body}
</Text>
</BlockStack>

<InlineStack gap="2" align="space-between" blockAlign="center">
<InlineStack gap="2" blockAlign="center">
<Button
asChild
size="sm"
variant="link"
className="px-0"
className={isCompact ? "px-0 text-xs" : "px-0"}
{...tracking("learning_hub.tip.browse_all")}
>
<Link to="/learn/tips">
Expand Down
6 changes: 5 additions & 1 deletion src/routes/Dashboard/DashboardHomeView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Link } from "@tanstack/react-router";

import { RunSection } from "@/components/Home/RunSection/RunSection";
import { TipOfTheDay } from "@/components/Learn/TipOfTheDay";
import { AnnouncementBanners } from "@/components/shared/AnnouncementBanners";
import { BlockStack, InlineStack } from "@/components/ui/layout";
import {
Expand Down Expand Up @@ -170,10 +171,13 @@ export function DashboardHomeView() {
<BlockStack gap="6">
<AnnouncementBanners />

<div className="grid grid-cols-3 gap-6 overflow-hidden">
<div className="w-full grid grid-cols-3 xl:grid-cols-6 gap-6 overflow-hidden">
<FavoritesPreview />
<RecentlyViewedPreview />
<RecentComponentsPreview />
<div className="col-span-3 max-w-4xl mx-auto">
<TipOfTheDay />
</div>
</div>

<BlockStack gap="3">
Expand Down
2 changes: 2 additions & 0 deletions src/routes/v2/pages/Editor/EditorV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { useRunsAndSubmissionWindow } from "./hooks/useRunsAndSubmissionWindow";
import { useSeedInitialDockLayoutFromPreset } from "./hooks/useSeedInitialDockLayoutFromPreset";
import { useSelectionWindowSync } from "./hooks/useSelectionWindowSync";
import { useSpecLifecycle } from "./hooks/useSpecLifecycle";
import { useTipOfTheDayWindow } from "./hooks/useTipOfTheDayWindow";
import { useUndoRedoKeyboard } from "./hooks/useUndoRedoKeyboard";
import { editorRegistry } from "./nodes";
import { EditorSessionProvider } from "./store/EditorSessionContext";
Expand Down Expand Up @@ -88,6 +89,7 @@ const PipelineEditor = withSuspenseWrapper(
useShortcutListener();
useEditorEscapeShortcut();
useDebugPanelWindow();
useTipOfTheDayWindow();
useSeedInitialDockLayoutFromPreset();

const activeSpec = navigation.activeSpec;
Expand Down
21 changes: 21 additions & 0 deletions src/routes/v2/pages/Editor/hooks/useTipOfTheDayWindow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useEffect } from "react";

import { TipOfTheDay } from "@/components/Learn/TipOfTheDay";
import { useSharedStores } from "@/routes/v2/shared/store/SharedStoreContext";

const TIP_OF_THE_DAY_WINDOW_ID = "tip-of-the-day";

export function useTipOfTheDayWindow() {
const { windows } = useSharedStores();
useEffect(() => {
if (windows.getWindowById(TIP_OF_THE_DAY_WINDOW_ID)) return;
windows.openWindow(<TipOfTheDay variant="compact" />, {
id: TIP_OF_THE_DAY_WINDOW_ID,
title: "Tip of the Day",
position: { x: 0, y: 820 },
size: { width: 280, height: 240 },
persisted: true,
defaultDockState: "left",
});
}, [windows]);
}
3 changes: 3 additions & 0 deletions src/routes/v2/shared/windows/viewPresets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface ViewPreset {

export const DEFAULT_DOCK_AREAS: PresetDockAreas = {
left: [
"tip-of-the-day",
"runs-and-submission",
"component-library",
"pipeline-tree",
Expand Down Expand Up @@ -46,6 +47,7 @@ export const DEFAULT_VIEW_PRESET: ViewPreset = {
"recent-runs",
"component-library",
"pipeline-details",
"tip-of-the-day",
]),
dockAreas: DEFAULT_DOCK_AREAS,
};
Expand All @@ -64,6 +66,7 @@ export const VIEW_PRESETS: ViewPreset[] = [
"pipeline-details",
"debug-panel",
"recent-runs",
"tip-of-the-day",
]),
dockAreas: DEFAULT_DOCK_AREAS,
},
Expand Down
Loading