feat: modernize widget experience

This commit is contained in:
Thomas Camlong authored and ajnart committed 2026-08-13 19:54:48 +02:00
1 parent 6331c88911
commit 1fa345edd1
165 files changed
+3698 -1649

No files matched your search

@@ -19,7 +19,7 @@ describe("stock summary", () => {
describe("stock layout", () => {
it("keeps compact widgets focused on symbol and price", () => {
expect(getStockLayout(320, 100, false)).toMatchObject({
expect(getStockLayout(320, 100)).toMatchObject({
showName: false,
showChange: false,
showRange: false,
@@ -28,12 +28,12 @@ describe("stock layout", () => {
});
it("reveals secondary data only when both axes have room", () => {
expect(getStockLayout(320, 160, false)).toMatchObject({
expect(getStockLayout(320, 160)).toMatchObject({
showName: false,
showChange: true,
showRange: true,
});
expect(getStockLayout(320, 220, false)).toMatchObject({
expect(getStockLayout(320, 220)).toMatchObject({
showName: true,
showChange: true,
showRange: true,
@@ -41,8 +41,8 @@ describe("stock layout", () => {
});
});
it("always exposes the complete advanced summary", () => {
expect(getStockLayout(120, 80, true)).toEqual({
it("exposes the complete summary when the widget is roomy", () => {
expect(getStockLayout(640, 360)).toEqual({
showName: true,
showChange: true,
showRange: true,
+6 -15
View File
@@ -38,22 +38,12 @@ export interface StockLayout {
priceOrder: 1 | 2;
}
export function getStockLayout(width: number, height: number, isAdvanced: boolean): StockLayout {
if (isAdvanced) {
return {
showName: true,
showChange: true,
showRange: true,
graphHeight: "75%",
priceOrder: 1,
};
}
export function getStockLayout(width: number, height: number): StockLayout {
return {
showName: width >= 300 && height >= 190,
showChange: width >= 260 && height >= 130,
showRange: width >= 220 && height >= 130,
graphHeight: height >= 220 ? "68%" : "48%",
graphHeight: height >= 320 ? "75%" : height >= 220 ? "68%" : "48%",
priceOrder: width >= 280 && height >= 120 ? 1 : 2,
};
}
@@ -71,13 +61,14 @@ export function getStockSummary(priceHistory: number[], previousClose: number):
};
}
export default function StockPriceWidget({ options, width, height, displayMode }: WidgetComponentProps<"stockPrice">) {
export default function StockPriceWidget({ options, width, height }: WidgetComponentProps<"stockPrice">) {
const t = useScopedI18n("widget.stockPrice");
const locale = useCurrentIntlLocale();
const numberFormatter = new Intl.NumberFormat(locale);
const theme = useMantineTheme();
const { data: result } = clientApi.widget.stockPrice.getPriceHistory.useQuery(options);
const { data: result, error } = clientApi.widget.stockPrice.getPriceHistory.useQuery(options);
if (error && !result) throw error;
if (!result) return <WidgetEmptyState />;
const { data } = result;
@@ -87,7 +78,7 @@ export default function StockPriceWidget({ options, width, height, displayMode }
const stockValuesChangePercentage = summary.changePercentage === null ? null : round(summary.changePercentage);
const stockGraphValues = summary.graphValues;
const trendColor = stockValuesChange > 0 ? "green.7" : stockValuesChange < 0 ? "red.7" : "gray.6";
const layout = getStockLayout(width, height, displayMode === "advanced");
const layout = getStockLayout(width, height);
return (
<Flex h="100%" w="100%">
+1
View File
@@ -12,6 +12,7 @@ const timeRangeOptions = stockPriceTimeFrames.range;
const timeIntervalOptions = stockPriceTimeFrames.interval;
export const { definition, componentLoader } = createWidgetDefinition("stockPrice", {
supportsAdvancedFocus: false,
icon: IconBuildingBank,
queryKey: [["widget", "stockPrice", "getPriceHistory"]],
queryMatcher: ({ input }, scope) =>