app: lazy load lean-qr

This commit is contained in:
k
2024-07-12 12:47:05 +02:00
parent 9077fee4d6
commit 46f8e3bafd
9 changed files with 134 additions and 78 deletions
+1
View File
@@ -43,6 +43,7 @@
- Chart
- Fixed series color being set to default ones after hovering the legend
- Fixed chart starting showing candlesticks and quickly switching to a line when it should've started directly with the line
- Separated the QRCode generator library from the main chunk and made it imported on click
- Settings
- Removed the horizontal scroll bar which was unintended
@@ -1,5 +1,3 @@
import { generate } from "lean-qr";
import { Button } from "./button";
export function ButtonShare({ qrcode }: { qrcode: RWS<string> }) {
@@ -7,16 +5,18 @@ export function ButtonShare({ qrcode }: { qrcode: RWS<string> }) {
<Button
title="Share"
icon={() => IconTablerShare}
onClick={() => {
qrcode.set(() =>
generate(document.location.href).toDataURL({
on: [0xff, 0xff, 0xff, 0xff],
off: [0x00, 0x00, 0x00, 0x00],
padX: 0,
padY: 0,
}),
);
}}
onClick={() =>
import("lean-qr").then(({ generate }) =>
qrcode.set(() =>
generate(document.location.href).toDataURL({
on: [0xff, 0xff, 0xff, 0xff],
off: [0x00, 0x00, 0x00, 0x00],
padX: 0,
padY: 0,
}),
),
)
}
/>
);
}
+38 -41
View File
@@ -2,49 +2,46 @@ import { touchScreen } from "/src/env";
export function Qrcode({ qrcode }: { qrcode: RWS<string> }) {
return (
<Show when={qrcode()}>
<div
class="absolute inset-0 z-50 flex size-full items-center justify-center bg-black/50 backdrop-blur-md"
onClick={() => {
qrcode.set("");
}}
>
<div class="flex size-full max-h-[80dvh] max-w-md flex-col justify-center space-y-8 px-8 pb-8 text-base">
<p class="pb-4 text-center text-3xl font-bold">Share</p>
<div
class="absolute inset-0 z-50 flex size-full items-center justify-center bg-black/50 backdrop-blur-md"
onClick={() => {
qrcode.set("");
}}
>
<div class="flex size-full max-h-[80dvh] max-w-md flex-col justify-center space-y-8 px-8 pb-8 text-base">
<p class="pb-4 text-center text-3xl font-bold">Share</p>
<p>
To share this page, you can either send the following QR Code with a
phone:
</p>
<div class="flex min-h-0 w-full flex-1 flex-col items-center justify-center">
<img
class="aspect-square min-h-0 flex-1 grow object-contain"
onClick={(event) => {
event?.stopPropagation();
}}
src={qrcode()}
style={{ "image-rendering": "pixelated" }}
/>
</div>
<div>
<p>Or if you prefer you can share this link instead:</p>
<a
onClick={(event) => {
event.stopPropagation();
}}
href={location.href}
>
{location.href}
</a>
</div>
<p>
{touchScreen ? "Touch" : "Click"} anywhere but on the QR Code to
exit.
</p>
<p>
To share this page, you can either send the following QR Code with a
phone:
</p>
<div class="flex min-h-0 w-full flex-1 flex-col items-center justify-center">
<img
class="aspect-square min-h-0 flex-1 grow object-contain"
onClick={(event) => {
event?.stopPropagation();
}}
src={qrcode()}
style={{ "image-rendering": "pixelated" }}
/>
</div>
<div>
<p>Or if you prefer you can share this link instead:</p>
<a
onClick={(event) => {
event.stopPropagation();
}}
href={location.href}
>
{location.href}
</a>
</div>
<p>
{touchScreen ? "Touch" : "Click"} anywhere but on the QR Code to exit.
</p>
</div>
</Show>
</div>
);
}
+10 -2
View File
@@ -18,7 +18,6 @@ import { FavoritesFrame } from "./components/frames/favorites";
import { FoldersFrame } from "./components/frames/folders";
import { HistoryFrame } from "./components/frames/history";
import { SettingsFrame } from "./components/frames/settings";
import { Qrcode } from "./components/qrcode";
import { StripDesktop, StripMobile } from "./components/strip";
import { Update } from "./components/update";
@@ -231,6 +230,12 @@ export function App() {
})),
);
const Qrcode = lazy(() =>
import("./components/qrcode").then((d) => ({
default: d.Qrcode,
})),
);
return (
<>
<Background
@@ -264,7 +269,10 @@ export function App() {
onTouchEnd={() => resizingBarStart.set(undefined)}
onTouchCancel={() => resizingBarStart.set(undefined)}
>
<Qrcode qrcode={qrcode} />
<Show when={qrcode()}>
<Qrcode qrcode={qrcode} />
</Show>
<Update />
<div class="flex size-full flex-col md:flex-row md:p-3 md:short:p-0">
+7 -8
View File
@@ -17,17 +17,16 @@ export function createResourceDataset<
>;
const baseURL = `${
// location.hostname === "localhost"
// ? "http://localhost:3110"
// : "https://api.satonomics.xyz"
"https://api.satonomics.xyz"
location.hostname === "localhost"
? "http://localhost:3111"
: "https://api.satonomics.xyz"
// "https://api.satonomics.xyz"
}${path}`;
const backupURL = `${
// location.hostname === "localhost"
// ? "http://localhost:3110"
// : "https://api.satonomics.xyz"
"https://api-bkp.satonomics.xyz"
location.hostname === "localhost"
? "http://localhost:3111"
: "https://api-bkp.satonomics.xyz"
}${path}`;
return createRoot((dispose) => {
@@ -43,17 +43,43 @@ function createPresetFolder({
key: AverageName;
}) {
return {
scale,
name,
description: "",
icon: IconTablerMathAvg,
title: `${name} Moving Average`,
top: [
tree: [
{
title: `SMA`,
color,
datasetPath: `/date-to-price-${key}-sma`,
scale,
name: "Average",
description: "",
icon: IconTablerMathAvg,
title: `${name} Moving Average`,
top: [
{
title: `SMA`,
color,
datasetPath: `/date-to-price-${key}-sma`,
},
],
},
{
scale,
name: "Ratio",
description: "",
icon: IconTablerMathXDivideY,
title: `${name} Moving Average Ratio`,
top: [
{
title: `SMA`,
color,
datasetPath: `/date-to-price-${key}-sma`,
},
],
bottom: [
{
title: `Ratio`,
color,
datasetPath: `/date-to-market-price-to-price-${key}-sma-ratio`,
},
],
},
],
} satisfies PartialPreset;
} satisfies PartialPresetFolder;
}
+1
View File
@@ -168,6 +168,7 @@ declare global {
const IconTablerLoop: (typeof import("~icons/tabler/loop.jsx"))["default"]
const IconTablerMail: typeof import('~icons/tabler/mail.jsx')['default']
const IconTablerMathAvg: typeof import('~icons/tabler/math-avg.jsx')['default']
const IconTablerMathXDivideY: typeof import('~icons/tabler/math-x-divide-y.jsx')['default']
const IconTablerMaximize: typeof import('~icons/tabler/maximize.jsx')['default']
const IconTablerMoneybag: typeof import('~icons/tabler/moneybag.jsx')['default']
const IconTablerMoodDollar: typeof import('~icons/tabler/mood-dollar.jsx')['default']
-1
View File
@@ -12,7 +12,6 @@ use crate::{
Databases, TxidToTxData, TxoutIndexToAddressIndex, TxoutIndexToAmount,
},
datasets::{AllDatasets, InsertData},
log,
states::{
AddressCohortsInputStates, AddressCohortsOutputStates, AddressCohortsRealizedStates,
States, UTXOCohortsOneShotStates, UTXOCohortsSentStates,
+30 -5
View File
@@ -138,11 +138,9 @@ impl PriceDatasets {
Ok(s)
}
pub fn compute(
&mut self,
&ComputeData { dates, heights }: &ComputeData,
circulating_supply: &mut BiMap<f64>,
) {
pub fn compute(&mut self, compute_data: &ComputeData, circulating_supply: &mut BiMap<f64>) {
let &ComputeData { dates, heights } = compute_data;
self.closes
.multi_insert_simple_transform(heights, dates, &mut self.ohlcs, &|ohlc| ohlc.close);
@@ -273,6 +271,33 @@ impl PriceDatasets {
(((last_value / previous_value).powf(1.0 / 4.0)) - 1.0) * 100.0
},
);
self.price_1w_sma_ratio
.compute(compute_data, &mut self.closes, &mut self.price_1w_sma);
self.price_1m_sma_ratio
.compute(compute_data, &mut self.closes, &mut self.price_1m_sma);
self.price_1y_sma_ratio
.compute(compute_data, &mut self.closes, &mut self.price_1y_sma);
self.price_2y_sma_ratio
.compute(compute_data, &mut self.closes, &mut self.price_2y_sma);
self.price_4y_sma_ratio
.compute(compute_data, &mut self.closes, &mut self.price_4y_sma);
self.price_8d_sma_ratio
.compute(compute_data, &mut self.closes, &mut self.price_8d_sma);
self.price_13d_sma_ratio
.compute(compute_data, &mut self.closes, &mut self.price_13d_sma);
self.price_21d_sma_ratio
.compute(compute_data, &mut self.closes, &mut self.price_21d_sma);
self.price_34d_sma_ratio
.compute(compute_data, &mut self.closes, &mut self.price_34d_sma);
self.price_55d_sma_ratio
.compute(compute_data, &mut self.closes, &mut self.price_55d_sma);
self.price_89d_sma_ratio
.compute(compute_data, &mut self.closes, &mut self.price_89d_sma);
self.price_144d_sma_ratio
.compute(compute_data, &mut self.closes, &mut self.price_144d_sma);
self.price_200w_sma_ratio
.compute(compute_data, &mut self.closes, &mut self.price_200w_sma);
}
pub fn get_date_ohlc(&mut self, date: WNaiveDate) -> color_eyre::Result<OHLC> {