phation 0.1.0 → 0.1.1

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.
Files changed (50) hide show
  1. package/README.md +69 -101
  2. package/package.json +13 -3
  3. package/server.json +36 -0
  4. package/animate/testset/eval.mjs +0 -24
  5. package/animate/testset/expected.json +0 -23
  6. package/animate/testset/holdout/commerce-delete-item-button.tsx +0 -38
  7. package/animate/testset/holdout/commerce-gallery.tsx +0 -96
  8. package/animate/testset/holdout/commerce-tile.tsx +0 -50
  9. package/animate/testset/holdout/shadcn-button-group-demo.tsx +0 -114
  10. package/animate/testset/holdout/shadcn-card-demo.tsx +0 -63
  11. package/animate/testset/holdout/shadcn-command-dialog.tsx +0 -87
  12. package/animate/testset/holdout/shadcn-drawer-dialog.tsx +0 -90
  13. package/animate/testset/holdout/shadcn-field-switch.tsx +0 -24
  14. package/animate/testset/holdout/shadcn-hover-card-demo.tsx +0 -40
  15. package/animate/testset/holdout/shadcn-mode-toggle.tsx +0 -40
  16. package/animate/testset/holdout/shadcn-toggle-group-demo.tsx +0 -22
  17. package/animate/testset/holdout.json +0 -14
  18. package/animate/testset/holdout2/chatbot-artifact-close-button.tsx +0 -30
  19. package/animate/testset/holdout2/chatbot-message-actions.tsx +0 -211
  20. package/animate/testset/holdout2/chatbot-sidebar-history-item.tsx +0 -132
  21. package/animate/testset/holdout2/chatbot-sidebar-toggle.tsx +0 -35
  22. package/animate/testset/holdout2/chatbot-suggested-actions.tsx +0 -82
  23. package/animate/testset/holdout2/chatbot-weather.tsx +0 -434
  24. package/animate/testset/holdout2/site-code-tabs.tsx +0 -26
  25. package/animate/testset/holdout2/site-copy-button.tsx +0 -121
  26. package/animate/testset/holdout2/site-github-link.tsx +0 -38
  27. package/animate/testset/holdout2/site-mobile-nav.tsx +0 -220
  28. package/animate/testset/holdout2/site-mode-switcher.tsx +0 -97
  29. package/animate/testset/holdout2/site-page-nav.tsx +0 -15
  30. package/animate/testset/holdout2.json +0 -15
  31. package/animate/testset/screens/commerce-cart-add-to-cart.tsx +0 -94
  32. package/animate/testset/screens/commerce-cart-modal.tsx +0 -256
  33. package/animate/testset/screens/commerce-navbar-mobile-menu.tsx +0 -104
  34. package/animate/testset/screens/commerce-product-variant-selector.tsx +0 -106
  35. package/animate/testset/screens/shadcn-accordion-demo.tsx +0 -61
  36. package/animate/testset/screens/shadcn-alert-dialog-demo.tsx +0 -35
  37. package/animate/testset/screens/shadcn-card-with-form.tsx +0 -59
  38. package/animate/testset/screens/shadcn-collapsible-demo.tsx +0 -46
  39. package/animate/testset/screens/shadcn-dialog-demo.tsx +0 -50
  40. package/animate/testset/screens/shadcn-drawer-demo.tsx +0 -136
  41. package/animate/testset/screens/shadcn-login-form.tsx +0 -71
  42. package/animate/testset/screens/shadcn-nav-main.tsx +0 -73
  43. package/animate/testset/screens/shadcn-section-cards.tsx +0 -102
  44. package/animate/testset/screens/shadcn-sheet-demo.tsx +0 -47
  45. package/animate/testset/screens/shadcn-switch-demo.tsx +0 -11
  46. package/animate/testset/screens/shadcn-tabs-demo.tsx +0 -80
  47. package/animate/testset/screens/taxonomy-main-nav.tsx +0 -61
  48. package/animate/testset/screens/taxonomy-post-item.tsx +0 -42
  49. package/animate/testset/screens/taxonomy-pricing.tsx +0 -69
  50. package/animate/testset/screens/taxonomy-user-account-nav.tsx +0 -65
@@ -1,132 +0,0 @@
1
- import Link from "next/link";
2
- import { memo, useCallback } from "react";
3
- import { useChatVisibility } from "@/hooks/use-chat-visibility";
4
- import type { Chat } from "@/lib/db/schema";
5
- import {
6
- DropdownMenu,
7
- DropdownMenuContent,
8
- DropdownMenuItem,
9
- DropdownMenuPortal,
10
- DropdownMenuSub,
11
- DropdownMenuSubContent,
12
- DropdownMenuSubTrigger,
13
- DropdownMenuTrigger,
14
- } from "../ui/dropdown-menu";
15
- import {
16
- SidebarMenuAction,
17
- SidebarMenuButton,
18
- SidebarMenuItem,
19
- } from "../ui/sidebar";
20
- import {
21
- CheckCircleFillIcon,
22
- GlobeIcon,
23
- LockIcon,
24
- MoreHorizontalIcon,
25
- ShareIcon,
26
- TrashIcon,
27
- } from "./icons";
28
-
29
- const PureChatItem = ({
30
- chat,
31
- isActive,
32
- onDelete,
33
- setOpenMobile,
34
- }: {
35
- chat: Chat;
36
- isActive: boolean;
37
- onDelete: (chatId: string) => void;
38
- setOpenMobile: (open: boolean) => void;
39
- }) => {
40
- const { visibilityType, setVisibilityType } = useChatVisibility({
41
- chatId: chat.id,
42
- initialVisibilityType: chat.visibility,
43
- });
44
- const closeMobile = useCallback(() => {
45
- setOpenMobile(false);
46
- }, [setOpenMobile]);
47
-
48
- const handleSetPrivate = useCallback(() => {
49
- setVisibilityType("private");
50
- }, [setVisibilityType]);
51
-
52
- const handleSetPublic = useCallback(() => {
53
- setVisibilityType("public");
54
- }, [setVisibilityType]);
55
-
56
- const handleDelete = useCallback(() => {
57
- onDelete(chat.id);
58
- }, [chat.id, onDelete]);
59
-
60
- return (
61
- <SidebarMenuItem>
62
- <SidebarMenuButton
63
- asChild
64
- className="h-8 rounded-none text-[13px] text-sidebar-foreground/50 transition-all duration-150 hover:bg-transparent hover:text-sidebar-foreground data-active:bg-transparent data-active:font-normal data-active:text-sidebar-foreground/50 data-[active=true]:text-sidebar-foreground data-[active=true]:font-medium data-[active=true]:border-b data-[active=true]:border-dashed data-[active=true]:border-sidebar-foreground/50"
65
- isActive={isActive}
66
- >
67
- <Link href={`/chat/${chat.id}`} onClick={closeMobile}>
68
- <span className="truncate">{chat.title}</span>
69
- </Link>
70
- </SidebarMenuButton>
71
-
72
- <DropdownMenu modal={true}>
73
- <DropdownMenuTrigger asChild>
74
- <SidebarMenuAction
75
- className="mr-0.5 rounded-md text-sidebar-foreground/50 ring-0 transition-colors duration-150 focus-visible:ring-0 hover:text-sidebar-foreground data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
76
- showOnHover={!isActive}
77
- >
78
- <MoreHorizontalIcon />
79
- <span className="sr-only">More</span>
80
- </SidebarMenuAction>
81
- </DropdownMenuTrigger>
82
-
83
- <DropdownMenuContent align="end" side="bottom">
84
- <DropdownMenuSub>
85
- <DropdownMenuSubTrigger className="cursor-pointer">
86
- <ShareIcon />
87
- <span>Share</span>
88
- </DropdownMenuSubTrigger>
89
- <DropdownMenuPortal>
90
- <DropdownMenuSubContent>
91
- <DropdownMenuItem
92
- className="cursor-pointer flex-row justify-between"
93
- onClick={handleSetPrivate}
94
- >
95
- <div className="flex flex-row items-center gap-2">
96
- <LockIcon size={12} />
97
- <span>Private</span>
98
- </div>
99
- {visibilityType === "private" ? (
100
- <CheckCircleFillIcon />
101
- ) : null}
102
- </DropdownMenuItem>
103
- <DropdownMenuItem
104
- className="cursor-pointer flex-row justify-between"
105
- onClick={handleSetPublic}
106
- >
107
- <div className="flex flex-row items-center gap-2">
108
- <GlobeIcon />
109
- <span>Public</span>
110
- </div>
111
- {visibilityType === "public" ? <CheckCircleFillIcon /> : null}
112
- </DropdownMenuItem>
113
- </DropdownMenuSubContent>
114
- </DropdownMenuPortal>
115
- </DropdownMenuSub>
116
-
117
- <DropdownMenuItem onSelect={handleDelete} variant="destructive">
118
- <TrashIcon />
119
- <span>Delete</span>
120
- </DropdownMenuItem>
121
- </DropdownMenuContent>
122
- </DropdownMenu>
123
- </SidebarMenuItem>
124
- );
125
- };
126
-
127
- export const ChatItem = memo(PureChatItem, (prevProps, nextProps) => {
128
- if (prevProps.isActive !== nextProps.isActive) {
129
- return false;
130
- }
131
- return true;
132
- });
@@ -1,35 +0,0 @@
1
- import type { ComponentProps } from "react";
2
-
3
- import { type SidebarTrigger, useSidebar } from "@/components/ui/sidebar";
4
- import {
5
- Tooltip,
6
- TooltipContent,
7
- TooltipTrigger,
8
- } from "@/components/ui/tooltip";
9
- import { Button } from "../ui/button";
10
- import { SidebarLeftIcon } from "./icons";
11
-
12
- export function SidebarToggle({
13
- className,
14
- }: ComponentProps<typeof SidebarTrigger>) {
15
- const { toggleSidebar } = useSidebar();
16
-
17
- return (
18
- <Tooltip>
19
- <TooltipTrigger asChild>
20
- <Button
21
- className={className}
22
- data-testid="sidebar-toggle-button"
23
- onClick={toggleSidebar}
24
- size="icon-sm"
25
- variant="outline"
26
- >
27
- <SidebarLeftIcon size={16} />
28
- </Button>
29
- </TooltipTrigger>
30
- <TooltipContent align="start" className="hidden md:block">
31
- Toggle Sidebar
32
- </TooltipContent>
33
- </Tooltip>
34
- );
35
- }
@@ -1,82 +0,0 @@
1
- "use client";
2
-
3
- import type { UseChatHelpers } from "@ai-sdk/react";
4
- import { motion } from "framer-motion";
5
- import { memo, useCallback } from "react";
6
- import { suggestions } from "@/lib/constants";
7
- import type { ChatMessage } from "@/lib/types";
8
- import { Suggestion } from "../ai-elements/suggestion";
9
- import type { VisibilityType } from "./visibility-selector";
10
-
11
- type SuggestedActionsProps = {
12
- chatId: string;
13
- sendMessage: UseChatHelpers<ChatMessage>["sendMessage"];
14
- selectedVisibilityType: VisibilityType;
15
- };
16
-
17
- function PureSuggestedActions({ chatId, sendMessage }: SuggestedActionsProps) {
18
- const suggestedActions = suggestions;
19
- const handleSuggestionClick = useCallback(
20
- (suggestion: string) => {
21
- window.history.pushState(
22
- {},
23
- "",
24
- `${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/chat/${chatId}`
25
- );
26
- sendMessage({
27
- parts: [{ text: suggestion, type: "text" }],
28
- role: "user",
29
- });
30
- },
31
- [chatId, sendMessage]
32
- );
33
-
34
- return (
35
- <div
36
- className="flex w-full gap-2.5 overflow-x-auto pb-1 sm:grid sm:grid-cols-2 sm:overflow-visible"
37
- data-testid="suggested-actions"
38
- style={{
39
- msOverflowStyle: "none",
40
- scrollbarWidth: "none",
41
- WebkitOverflowScrolling: "touch",
42
- }}
43
- >
44
- {suggestedActions.map((suggestedAction, index) => (
45
- <motion.div
46
- animate={{ opacity: 1, y: 0 }}
47
- className="min-w-[200px] shrink-0 sm:min-w-0 sm:shrink"
48
- exit={{ opacity: 0, y: 16 }}
49
- initial={{ opacity: 0, y: 16 }}
50
- key={suggestedAction}
51
- transition={{
52
- delay: 0.06 * index,
53
- duration: 0.4,
54
- ease: [0.22, 1, 0.36, 1],
55
- }}
56
- >
57
- <Suggestion
58
- className="h-auto w-full whitespace-nowrap rounded-xl border border-border/50 bg-card/30 px-4 py-3 text-left text-[12px] leading-relaxed text-muted-foreground transition-all duration-200 sm:whitespace-normal sm:p-4 sm:text-[13px] hover:-translate-y-0.5 hover:bg-card/60 hover:text-foreground hover:shadow-[var(--shadow-card)]"
59
- onClick={handleSuggestionClick}
60
- suggestion={suggestedAction}
61
- >
62
- {suggestedAction}
63
- </Suggestion>
64
- </motion.div>
65
- ))}
66
- </div>
67
- );
68
- }
69
-
70
- export const SuggestedActions = memo(
71
- PureSuggestedActions,
72
- (prevProps, nextProps) => {
73
- if (prevProps.chatId !== nextProps.chatId) {
74
- return false;
75
- }
76
- if (prevProps.selectedVisibilityType !== nextProps.selectedVisibilityType) {
77
- return false;
78
- }
79
-
80
- return true;
81
- }
82
- );
@@ -1,434 +0,0 @@
1
- "use client";
2
-
3
- import cx from "classnames";
4
- import { format, isWithinInterval } from "date-fns";
5
- import { useEffect, useState } from "react";
6
-
7
- const SunIcon = ({ size = 40 }: { size?: number }) => (
8
- <svg fill="none" height={size} viewBox="0 0 24 24" width={size}>
9
- <circle cx="12" cy="12" fill="currentColor" r="5" />
10
- <line stroke="currentColor" strokeWidth="2" x1="12" x2="12" y1="1" y2="3" />
11
- <line
12
- stroke="currentColor"
13
- strokeWidth="2"
14
- x1="12"
15
- x2="12"
16
- y1="21"
17
- y2="23"
18
- />
19
- <line
20
- stroke="currentColor"
21
- strokeWidth="2"
22
- x1="4.22"
23
- x2="5.64"
24
- y1="4.22"
25
- y2="5.64"
26
- />
27
- <line
28
- stroke="currentColor"
29
- strokeWidth="2"
30
- x1="18.36"
31
- x2="19.78"
32
- y1="18.36"
33
- y2="19.78"
34
- />
35
- <line stroke="currentColor" strokeWidth="2" x1="1" x2="3" y1="12" y2="12" />
36
- <line
37
- stroke="currentColor"
38
- strokeWidth="2"
39
- x1="21"
40
- x2="23"
41
- y1="12"
42
- y2="12"
43
- />
44
- <line
45
- stroke="currentColor"
46
- strokeWidth="2"
47
- x1="4.22"
48
- x2="5.64"
49
- y1="19.78"
50
- y2="18.36"
51
- />
52
- <line
53
- stroke="currentColor"
54
- strokeWidth="2"
55
- x1="18.36"
56
- x2="19.78"
57
- y1="5.64"
58
- y2="4.22"
59
- />
60
- </svg>
61
- );
62
-
63
- const MoonIcon = ({ size = 40 }: { size?: number }) => (
64
- <svg fill="none" height={size} viewBox="0 0 24 24" width={size}>
65
- <path
66
- d="M21 12.79A9 9 0 1 1 11.21 3A7 7 0 0 0 21 12.79z"
67
- fill="currentColor"
68
- />
69
- </svg>
70
- );
71
-
72
- const CloudIcon = ({ size = 24 }: { size?: number }) => (
73
- <svg fill="none" height={size} viewBox="0 0 24 24" width={size}>
74
- <path
75
- d="M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z"
76
- fill="none"
77
- stroke="currentColor"
78
- strokeWidth="2"
79
- />
80
- </svg>
81
- );
82
-
83
- type WeatherAtLocation = {
84
- latitude: number;
85
- longitude: number;
86
- generationtime_ms: number;
87
- utc_offset_seconds: number;
88
- timezone: string;
89
- timezone_abbreviation: string;
90
- elevation: number;
91
- cityName?: string;
92
- current_units: {
93
- time: string;
94
- interval: string;
95
- temperature_2m: string;
96
- };
97
- current: {
98
- time: string;
99
- interval: number;
100
- temperature_2m: number;
101
- };
102
- hourly_units: {
103
- time: string;
104
- temperature_2m: string;
105
- };
106
- hourly: {
107
- time: string[];
108
- temperature_2m: number[];
109
- };
110
- daily_units: {
111
- time: string;
112
- sunrise: string;
113
- sunset: string;
114
- };
115
- daily: {
116
- time: string[];
117
- sunrise: string[];
118
- sunset: string[];
119
- };
120
- };
121
-
122
- const SAMPLE = {
123
- current: { interval: 900, temperature_2m: 29.3, time: "2024-10-07T19:30" },
124
- current_units: { interval: "seconds", temperature_2m: "°C", time: "iso8601" },
125
- daily: {
126
- sunrise: [
127
- "2024-10-07T07:15",
128
- "2024-10-08T07:16",
129
- "2024-10-09T07:17",
130
- "2024-10-10T07:18",
131
- "2024-10-11T07:19",
132
- ],
133
- sunset: [
134
- "2024-10-07T19:00",
135
- "2024-10-08T18:58",
136
- "2024-10-09T18:57",
137
- "2024-10-10T18:55",
138
- "2024-10-11T18:54",
139
- ],
140
- time: [
141
- "2024-10-07",
142
- "2024-10-08",
143
- "2024-10-09",
144
- "2024-10-10",
145
- "2024-10-11",
146
- ],
147
- },
148
- daily_units: {
149
- sunrise: "iso8601",
150
- sunset: "iso8601",
151
- time: "iso8601",
152
- },
153
- elevation: 18,
154
- generationtime_ms: 0.027_894_973_754_882_812,
155
- hourly: {
156
- temperature_2m: [
157
- 36.6, 32.8, 29.5, 28.6, 29.2, 28.2, 27.5, 26.6, 26.5, 26, 25, 23.5, 23.9,
158
- 24.2, 22.9, 21, 24, 28.1, 31.4, 33.9, 32.1, 28.9, 26.9, 25.2, 23, 21.1,
159
- 19.6, 18.6, 17.7, 16.8, 16.2, 15.5, 14.9, 14.4, 14.2, 13.7, 13.3, 12.9,
160
- 12.5, 13.5, 15.8, 17.7, 19.6, 21, 21.9, 22.3, 22, 20.7, 18.9, 17.9, 17.3,
161
- 17, 16.7, 16.2, 15.6, 15.2, 15, 15, 15.1, 14.8, 14.8, 14.9, 14.7, 14.8,
162
- 15.3, 16.2, 17.9, 19.6, 20.5, 21.6, 21, 20.7, 19.3, 18.7, 18.4, 17.9,
163
- 17.3, 17, 17, 16.8, 16.4, 16.2, 16, 15.8, 15.7, 15.4, 15.4, 16.1, 16.7,
164
- 17, 18.6, 19, 19.5, 19.4, 18.5, 17.9, 17.5, 16.7, 16.3, 16.1,
165
- ],
166
- time: [
167
- "2024-10-07T00:00",
168
- "2024-10-07T01:00",
169
- "2024-10-07T02:00",
170
- "2024-10-07T03:00",
171
- "2024-10-07T04:00",
172
- "2024-10-07T05:00",
173
- "2024-10-07T06:00",
174
- "2024-10-07T07:00",
175
- "2024-10-07T08:00",
176
- "2024-10-07T09:00",
177
- "2024-10-07T10:00",
178
- "2024-10-07T11:00",
179
- "2024-10-07T12:00",
180
- "2024-10-07T13:00",
181
- "2024-10-07T14:00",
182
- "2024-10-07T15:00",
183
- "2024-10-07T16:00",
184
- "2024-10-07T17:00",
185
- "2024-10-07T18:00",
186
- "2024-10-07T19:00",
187
- "2024-10-07T20:00",
188
- "2024-10-07T21:00",
189
- "2024-10-07T22:00",
190
- "2024-10-07T23:00",
191
- "2024-10-08T00:00",
192
- "2024-10-08T01:00",
193
- "2024-10-08T02:00",
194
- "2024-10-08T03:00",
195
- "2024-10-08T04:00",
196
- "2024-10-08T05:00",
197
- "2024-10-08T06:00",
198
- "2024-10-08T07:00",
199
- "2024-10-08T08:00",
200
- "2024-10-08T09:00",
201
- "2024-10-08T10:00",
202
- "2024-10-08T11:00",
203
- "2024-10-08T12:00",
204
- "2024-10-08T13:00",
205
- "2024-10-08T14:00",
206
- "2024-10-08T15:00",
207
- "2024-10-08T16:00",
208
- "2024-10-08T17:00",
209
- "2024-10-08T18:00",
210
- "2024-10-08T19:00",
211
- "2024-10-08T20:00",
212
- "2024-10-08T21:00",
213
- "2024-10-08T22:00",
214
- "2024-10-08T23:00",
215
- "2024-10-09T00:00",
216
- "2024-10-09T01:00",
217
- "2024-10-09T02:00",
218
- "2024-10-09T03:00",
219
- "2024-10-09T04:00",
220
- "2024-10-09T05:00",
221
- "2024-10-09T06:00",
222
- "2024-10-09T07:00",
223
- "2024-10-09T08:00",
224
- "2024-10-09T09:00",
225
- "2024-10-09T10:00",
226
- "2024-10-09T11:00",
227
- "2024-10-09T12:00",
228
- "2024-10-09T13:00",
229
- "2024-10-09T14:00",
230
- "2024-10-09T15:00",
231
- "2024-10-09T16:00",
232
- "2024-10-09T17:00",
233
- "2024-10-09T18:00",
234
- "2024-10-09T19:00",
235
- "2024-10-09T20:00",
236
- "2024-10-09T21:00",
237
- "2024-10-09T22:00",
238
- "2024-10-09T23:00",
239
- "2024-10-10T00:00",
240
- "2024-10-10T01:00",
241
- "2024-10-10T02:00",
242
- "2024-10-10T03:00",
243
- "2024-10-10T04:00",
244
- "2024-10-10T05:00",
245
- "2024-10-10T06:00",
246
- "2024-10-10T07:00",
247
- "2024-10-10T08:00",
248
- "2024-10-10T09:00",
249
- "2024-10-10T10:00",
250
- "2024-10-10T11:00",
251
- "2024-10-10T12:00",
252
- "2024-10-10T13:00",
253
- "2024-10-10T14:00",
254
- "2024-10-10T15:00",
255
- "2024-10-10T16:00",
256
- "2024-10-10T17:00",
257
- "2024-10-10T18:00",
258
- "2024-10-10T19:00",
259
- "2024-10-10T20:00",
260
- "2024-10-10T21:00",
261
- "2024-10-10T22:00",
262
- "2024-10-10T23:00",
263
- "2024-10-11T00:00",
264
- "2024-10-11T01:00",
265
- "2024-10-11T02:00",
266
- "2024-10-11T03:00",
267
- ],
268
- },
269
- hourly_units: { temperature_2m: "°C", time: "iso8601" },
270
- latitude: 37.763_283,
271
- longitude: -122.412_86,
272
- timezone: "GMT",
273
- timezone_abbreviation: "GMT",
274
- utc_offset_seconds: 0,
275
- };
276
-
277
- function n(num: number): number {
278
- return Math.ceil(num);
279
- }
280
-
281
- export function Weather({
282
- weatherAtLocation = SAMPLE,
283
- }: {
284
- weatherAtLocation?: WeatherAtLocation;
285
- }) {
286
- const currentHigh = Math.max(
287
- ...weatherAtLocation.hourly.temperature_2m.slice(0, 24)
288
- );
289
- const currentLow = Math.min(
290
- ...weatherAtLocation.hourly.temperature_2m.slice(0, 24)
291
- );
292
-
293
- const isDay = isWithinInterval(new Date(weatherAtLocation.current.time), {
294
- end: new Date(weatherAtLocation.daily.sunset[0]),
295
- start: new Date(weatherAtLocation.daily.sunrise[0]),
296
- });
297
-
298
- const [isMobile, setIsMobile] = useState(false);
299
-
300
- useEffect(() => {
301
- const handleResize = () => {
302
- setIsMobile(window.innerWidth < 768);
303
- };
304
-
305
- handleResize();
306
- window.addEventListener("resize", handleResize);
307
-
308
- return () => window.removeEventListener("resize", handleResize);
309
- }, []);
310
-
311
- const hoursToShow = isMobile ? 5 : 6;
312
-
313
- const currentTimeIndex = weatherAtLocation.hourly.time.findIndex(
314
- (time) => new Date(time) >= new Date(weatherAtLocation.current.time)
315
- );
316
-
317
- const displayTimes = weatherAtLocation.hourly.time.slice(
318
- currentTimeIndex,
319
- currentTimeIndex + hoursToShow
320
- );
321
- const displayTemperatures = weatherAtLocation.hourly.temperature_2m.slice(
322
- currentTimeIndex,
323
- currentTimeIndex + hoursToShow
324
- );
325
-
326
- const location =
327
- weatherAtLocation.cityName ||
328
- `${weatherAtLocation.latitude?.toFixed(1)}°, ${weatherAtLocation.longitude?.toFixed(1)}°`;
329
-
330
- return (
331
- <div
332
- className={cx(
333
- "relative flex w-full flex-col gap-3 overflow-hidden rounded-2xl p-4 shadow-lg backdrop-blur-sm",
334
- {
335
- "bg-gradient-to-br from-sky-400 via-blue-500 to-blue-600": isDay,
336
- },
337
- {
338
- "bg-gradient-to-br from-indigo-900 via-purple-900 to-slate-900":
339
- !isDay,
340
- }
341
- )}
342
- >
343
- <div className="absolute inset-0 bg-white/10 backdrop-blur-sm" />
344
-
345
- <div className="relative z-10">
346
- <div className="mb-2 flex items-center justify-between">
347
- <div className="font-medium text-white/80 text-xs">{location}</div>
348
- <div className="text-white/60 text-xs">
349
- {format(new Date(weatherAtLocation.current.time), "MMM d, h:mm a")}
350
- </div>
351
- </div>
352
-
353
- <div className="mb-3 flex items-center justify-between">
354
- <div className="flex items-center gap-3">
355
- <div
356
- className={cx("text-white/90", {
357
- "text-blue-200": !isDay,
358
- "text-yellow-200": isDay,
359
- })}
360
- >
361
- {isDay ? <SunIcon size={32} /> : <MoonIcon size={32} />}
362
- </div>
363
- <div className="font-light text-3xl text-white">
364
- {n(weatherAtLocation.current.temperature_2m)}
365
- <span className="text-lg text-white/80">
366
- {weatherAtLocation.current_units.temperature_2m}
367
- </span>
368
- </div>
369
- </div>
370
-
371
- <div className="text-right">
372
- <div className="font-medium text-white/90 text-xs">
373
- H: {n(currentHigh)}°
374
- </div>
375
- <div className="text-white/70 text-xs">L: {n(currentLow)}°</div>
376
- </div>
377
- </div>
378
-
379
- <div className="rounded-xl bg-white/10 p-3 backdrop-blur-sm">
380
- <div className="mb-2 font-medium text-white/80 text-xs">
381
- Hourly Forecast
382
- </div>
383
- <div className="flex justify-between gap-1">
384
- {displayTimes.map((time, index) => {
385
- const hourTime = new Date(time);
386
- const isCurrentHour =
387
- hourTime.getHours() === new Date().getHours();
388
-
389
- return (
390
- <div
391
- className={cx(
392
- "flex min-w-0 flex-1 flex-col items-center gap-1 rounded-md px-1 py-1.5",
393
- {
394
- "bg-white/20": isCurrentHour,
395
- }
396
- )}
397
- key={time}
398
- >
399
- <div className="font-medium text-white/70 text-xs">
400
- {index === 0 ? "Now" : format(hourTime, "ha")}
401
- </div>
402
-
403
- <div
404
- className={cx("text-white/60", {
405
- "text-blue-200": !isDay,
406
- "text-yellow-200": isDay,
407
- })}
408
- >
409
- <CloudIcon size={16} />
410
- </div>
411
-
412
- <div className="font-medium text-white text-xs">
413
- {n(displayTemperatures[index])}°
414
- </div>
415
- </div>
416
- );
417
- })}
418
- </div>
419
- </div>
420
-
421
- <div className="mt-2 flex justify-between text-white/60 text-xs">
422
- <div>
423
- Sunrise:{" "}
424
- {format(new Date(weatherAtLocation.daily.sunrise[0]), "h:mm a")}
425
- </div>
426
- <div>
427
- Sunset:{" "}
428
- {format(new Date(weatherAtLocation.daily.sunset[0]), "h:mm a")}
429
- </div>
430
- </div>
431
- </div>
432
- </div>
433
- );
434
- }