Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | 5x 5x 2x 5x 4x 5x 1x 1x 1x 5x 2x 2x 1x 1x 1x 1x 1x 1x 5x 1x 1x 1x 1x 5x 1x 1x 1x 5x 2x 2x 2x 1x 1x 1x 5x 3x 5x 3x 2x 5x 3x 2x 1x 5x 3x 3x 1x 2x 2x 3x 3x 3x | import {
MarketPayload,
RSSConfig,
RSSItem,
RSSPayload,
WeatherPayload,
} from "@/objects/Dashboard";
import {
Cloud,
CloudDrizzle,
CloudFog,
CloudLightning,
CloudRain,
CloudSnow,
CloudSun,
ExternalLink,
HelpCircle,
Snowflake,
Sun,
} from "lucide-react";
import React from "react";
import {
Area,
AreaChart,
ResponsiveContainer,
Tooltip,
YAxis,
} from "recharts";
import { WidgetBodyProps } from "./types";
import { parseServerDate } from "@/util/time";
// ─── Weather ──────────────────────────────────────────────────────────────────
/** WMO condition keys from the backend → a glyph. */
const WEATHER_ICONS: Record<string, React.ElementType> = {
clear: Sun,
"partly-cloudy": CloudSun,
cloudy: Cloud,
fog: CloudFog,
drizzle: CloudDrizzle,
rain: CloudRain,
sleet: Snowflake,
snow: CloudSnow,
thunder: CloudLightning,
unknown: HelpCircle,
};
const weatherIcon = (key: string): React.ElementType =>
WEATHER_ICONS[key] ?? HelpCircle;
const temp = (value: number | null, unit: string): string =>
value === null || value === undefined ? "—" : `${Math.round(value)}${unit}`;
const dayName = (iso: string): string => {
const date = parseServerDate(iso);
Iif (Number.isNaN(date.getTime())) return iso;
return date.toLocaleDateString(undefined, { weekday: "short" });
};
export const WeatherWidgetBody: React.FC<WidgetBodyProps> = ({ widget }) => {
const payload = widget.cache_payload as unknown as WeatherPayload | null;
if (!payload?.current) {
return (
<p className="text-xs text-gray-400 dark:text-gray-500 italic">
No forecast yet — this loads on its next refresh.
</p>
);
}
const { current, days, units } = payload;
const CurrentIcon = weatherIcon(current.icon);
return (
<div className="h-full flex flex-col">
<div className="flex items-center gap-3">
<CurrentIcon
className={`w-9 h-9 shrink-0 ${
current.is_day
? "text-amber-500"
: "text-indigo-400 dark:text-indigo-300"
}`}
/>
<div className="min-w-0">
<p className="text-2xl font-bold leading-none text-gray-900 dark:text-white">
{temp(current.temperature, units.temperature)}
</p>
<p className="text-xs text-gray-500 dark:text-gray-400 truncate">
{current.label}
{payload.location_name ? ` · ${payload.location_name}` : ""}
</p>
</div>
</div>
<div className="mt-2 flex flex-wrap gap-x-3 gap-y-0.5 text-[11px] text-gray-400 dark:text-gray-500">
{current.feels_like !== null && (
<span>Feels {temp(current.feels_like, units.temperature)}</span>
)}
{current.humidity !== null && <span>{current.humidity}% humidity</span>}
{current.wind_speed !== null && (
<span>
{Math.round(current.wind_speed)} {units.wind_speed}
</span>
)}
</div>
{days.length > 0 && (
<div className="mt-3 pt-2 border-t border-gray-100 dark:border-gray-700/60 grid grid-cols-5 gap-1">
{days.slice(0, 5).map((day) => {
const DayIcon = weatherIcon(day.icon);
return (
<div
key={day.date}
className="flex flex-col items-center gap-0.5 text-center"
title={`${day.label}${
day.precipitation_probability !== null
? ` · ${day.precipitation_probability}% rain`
: ""
}`}
>
<span className="text-[10px] text-gray-400 dark:text-gray-500">
{dayName(day.date)}
</span>
<DayIcon className="w-3.5 h-3.5 text-gray-500 dark:text-gray-400" />
<span className="text-[10px] font-medium text-gray-700 dark:text-gray-200 tabular-nums">
{temp(day.max, "")}
</span>
<span className="text-[10px] text-gray-400 dark:text-gray-500 tabular-nums">
{temp(day.min, "")}
</span>
</div>
);
})}
</div>
)}
</div>
);
};
// ─── RSS ──────────────────────────────────────────────────────────────────────
const publishedAgo = (raw: string): string => {
Iif (!raw) return "";
const date = parseServerDate(raw);
Iif (Number.isNaN(date.getTime())) return "";
return date.toLocaleDateString(undefined, {
month: "short",
day: "numeric",
});
};
const FeedItem: React.FC<{ item: RSSItem; showSummary: boolean }> = ({
item,
showSummary,
}) => {
const body = (
<>
<p className="text-xs font-medium leading-snug text-gray-800 dark:text-gray-100 group-hover:text-blue-600 dark:group-hover:text-blue-400 line-clamp-2">
{item.title}
</p>
{showSummary && item.summary && (
<p className="mt-0.5 text-[11px] leading-snug text-gray-500 dark:text-gray-400 line-clamp-2">
{item.summary}
</p>
)}
{item.published && (
<p className="mt-0.5 text-[10px] text-gray-400 dark:text-gray-500">
{publishedAgo(item.published)}
</p>
)}
</>
);
Iif (!item.link) {
return <div className="py-1.5">{body}</div>;
}
return (
<a
// Feed links leave the app, and the target is a third party — noopener
// and noreferrer both matter here.
href={item.link}
target="_blank"
rel="noopener noreferrer"
className="group block py-1.5"
>
{body}
</a>
);
};
export const RSSWidgetBody: React.FC<WidgetBodyProps> = ({ widget }) => {
const payload = widget.cache_payload as unknown as RSSPayload | null;
const config = widget.config as unknown as RSSConfig;
if (!payload?.items?.length) {
return (
<p className="text-xs text-gray-400 dark:text-gray-500 italic">
No headlines yet — this loads on its next refresh.
</p>
);
}
return (
<div className="h-full flex flex-col">
<div className="flex-1 min-h-0 divide-y divide-gray-100 dark:divide-gray-700/60">
{payload.items.map((item, index) => (
<FeedItem
key={`${item.link}-${index}`}
item={item}
showSummary={config?.show_summaries !== false}
/>
))}
</div>
{payload.feed_link && (
<a
href={payload.feed_link}
target="_blank"
rel="noopener noreferrer"
className="mt-2 pt-2 border-t border-gray-100 dark:border-gray-700/60 inline-flex items-center gap-1 text-[11px] text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300"
>
{payload.feed_title}
<ExternalLink className="w-2.5 h-2.5" />
</a>
)}
</div>
);
};
// ─── Market ───────────────────────────────────────────────────────────────────
const money = (value: number | null): string =>
value === null || value === undefined ? "—" : value.toFixed(2);
const signed = (value: number | null): string => {
if (value === null || value === undefined) return "—";
return `${value >= 0 ? "+" : ""}${value.toFixed(2)}`;
};
const moveClass = (value: number | null): string => {
if (value === null || value === undefined) return "text-gray-400";
if (value > 0) return "text-emerald-600 dark:text-emerald-400";
Eif (value < 0) return "text-red-600 dark:text-red-400";
return "text-gray-500 dark:text-gray-400";
};
export const MarketWidgetBody: React.FC<WidgetBodyProps> = ({ widget }) => {
const payload = widget.cache_payload as unknown as MarketPayload | null;
// A missing key is a setup step, not a failure — the frame shows the
// backend's message, which names the vendor and where to get one.
if (!payload?.quotes?.length && !payload?.series?.length) {
return (
<p className="text-xs text-gray-400 dark:text-gray-500 italic">
No market data yet — this loads on its next refresh.
</p>
);
}
const { quotes, series } = payload;
const up =
series.length > 1 &&
(series[series.length - 1].close ?? 0) >= (series[0].close ?? 0);
const lineColour = up ? "#10b981" : "#f43f5e";
return (
<div className="h-full flex flex-col">
<ul className="divide-y divide-gray-100 dark:divide-gray-700/60">
{quotes.map((quote) => (
<li
key={quote.symbol}
className="flex items-baseline justify-between gap-2 py-1"
>
<span className="text-xs font-semibold text-gray-800 dark:text-gray-100">
{quote.symbol}
</span>
<span className="flex items-baseline gap-2">
<span className="text-xs tabular-nums text-gray-700 dark:text-gray-200">
{money(quote.price)}
</span>
<span
className={`text-[11px] tabular-nums ${moveClass(
quote.change_percent,
)}`}
>
{signed(quote.change_percent)}%
</span>
</span>
</li>
))}
</ul>
{series.length > 1 && (
<div className="mt-2 flex-1 min-h-[60px]">
<p className="text-[10px] text-gray-400 dark:text-gray-500 mb-0.5">
{payload.series_symbol} · last {series.length} sessions
</p>
<ResponsiveContainer width="100%" height="100%">
<AreaChart
data={series}
margin={{ top: 2, right: 2, bottom: 0, left: 0 }}
>
<defs>
<linearGradient
id={`mkt-${widget.id}`}
x1="0"
y1="0"
x2="0"
y2="1"
>
<stop offset="0%" stopColor={lineColour} stopOpacity={0.3} />
<stop offset="100%" stopColor={lineColour} stopOpacity={0.02} />
</linearGradient>
</defs>
<YAxis hide domain={["dataMin", "dataMax"]} />
<Tooltip
contentStyle={{
fontSize: 11,
borderRadius: 8,
border: "1px solid rgba(148,163,184,0.3)",
}}
/>
<Area
type="monotone"
dataKey="close"
stroke={lineColour}
strokeWidth={1.5}
fill={`url(#mkt-${widget.id})`}
dot={false}
/>
</AreaChart>
</ResponsiveContainer>
</div>
)}
{payload.errors?.length > 0 && (
<p className="mt-1 text-[10px] text-amber-600 dark:text-amber-400 line-clamp-2">
{payload.errors.join("; ")}
</p>
)}
{payload.delayed && (
<p className="mt-1 text-[10px] text-gray-400 dark:text-gray-500">
Delayed / end-of-day prices. Not investment advice.
</p>
)}
</div>
);
};
|