Skip to content

Commit 46ac814

Browse files
committed
feat: introduce LinkButton component, refactor external link handling, and simplify StockDetail interface.
1 parent 0e496cc commit 46ac814

File tree

4 files changed

+40
-44
lines changed

4 files changed

+40
-44
lines changed

frontend/src/app/home/stock.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useNavigate, useParams } from "react-router";
44
import { useGetStockDetail, useRemoveStockFromWatchlist } from "@/api/stock";
55
import TradingViewAdvancedChart from "@/components/tradingview/tradingview-advanced-chart";
66
import { Button } from "@/components/ui/button";
7+
import LinkButton from "@/components/valuecell/button/link-button";
78
import type { Route } from "./+types/stock";
89

910
function Stock() {
@@ -82,12 +83,6 @@ function Stock() {
8283
/>
8384
</div>
8485

85-
{/* <div className="flex flex-col gap-4">
86-
<h2 className="font-bold text-lg">Details</h2>
87-
88-
<StockDetailsList data={detailsData} />
89-
</div> */}
90-
9186
<div className="flex flex-col gap-4">
9287
<h2 className="font-bold text-lg">About</h2>
9388

@@ -112,14 +107,12 @@ function Stock() {
112107
{stockDetailData.properties.website && (
113108
<div className="col-span-2">
114109
<span className="text-muted-foreground">Website:</span>
115-
<a
116-
href={stockDetailData.properties.website}
117-
target="_blank"
118-
rel="noopener noreferrer"
119-
className="ml-2 text-blue-600 hover:underline"
110+
<LinkButton
111+
url={stockDetailData.properties.website}
112+
className="ml-2 text-blue-600"
120113
>
121114
{stockDetailData.properties.website}
122-
</a>
115+
</LinkButton>
123116
</div>
124117
)}
125118
</div>

frontend/src/app/setting/components/models/model-detail.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { DialogDescription } from "@radix-ui/react-dialog";
22
import { useForm } from "@tanstack/react-form";
3-
import { openUrl } from "@tauri-apps/plugin-opener";
43
import { Eye, EyeOff, Plus, Trash2 } from "lucide-react";
54
import { useEffect, useState } from "react";
65
import { z } from "zod";
@@ -35,6 +34,7 @@ import {
3534
InputGroupInput,
3635
} from "@/components/ui/input-group";
3736
import { Switch } from "@/components/ui/switch";
37+
import LinkButton from "@/components/valuecell/button/link-button";
3838
import { useTauriInfo } from "@/hooks/use-tauri-info";
3939

4040
const configSchema = z.object({
@@ -206,17 +206,12 @@ export function ModelDetail({ provider }: ModelDetailProps) {
206206
</InputGroupButton>
207207
</InputGroupAddon>
208208
</InputGroup>
209-
<button
210-
type="button"
211-
onClick={() =>
212-
isTauriApp
213-
? openUrl(providerDetail.api_key_url)
214-
: window.open(providerDetail.api_key_url, "_blank")
215-
}
216-
className="w-fit! cursor-pointer text-sm underline underline-offset-4 hover:text-gray-700"
209+
<LinkButton
210+
className="w-fit! hover:text-gray-700"
211+
url={providerDetail.api_key_url}
217212
>
218213
Click here to get the API key
219-
</button>
214+
</LinkButton>
220215
<FieldError errors={field.state.meta.errors} />
221216
</Field>
222217
)}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { openUrl } from "@tauri-apps/plugin-opener";
2+
import type React from "react";
3+
import type { FC } from "react";
4+
import { useTauriInfo } from "@/hooks/use-tauri-info";
5+
import { cn } from "@/lib/utils";
6+
7+
type LinkButtonProps = {
8+
url: string;
9+
className?: string;
10+
children: React.ReactNode;
11+
};
12+
13+
const LinkButton: FC<LinkButtonProps> = ({ className, url, children }) => {
14+
const { isTauriApp } = useTauriInfo();
15+
16+
return (
17+
<button
18+
type="button"
19+
className={cn(
20+
"cursor-pointer text-sm underline underline-offset-4",
21+
className,
22+
)}
23+
onClick={() => (isTauriApp ? openUrl(url) : window.open(url, "_blank"))}
24+
>
25+
{children}
26+
</button>
27+
);
28+
};
29+
30+
export default LinkButton;

frontend/src/types/stock.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,7 @@ export interface StockHistory {
5353
}
5454

5555
export interface StockDetail {
56-
ticker: string;
57-
asset_type: "stock" | "etf" | "index" | "crypto";
58-
asset_type_display: string;
59-
names: {
60-
"en-US": string;
61-
"en-GB": string;
62-
"zh-Hans": string;
63-
"zh-Hant": string;
64-
};
6556
display_name: string;
66-
descriptions: Record<string, string>;
67-
market_info: {
68-
exchange: string;
69-
country: string;
70-
currency: StockCurrency;
71-
timezone: string;
72-
trading_hours: string | null;
73-
market_status: string;
74-
};
75-
source_mappings: Record<string, string>;
7657
properties: {
7758
sector: string;
7859
industry: string;
@@ -83,7 +64,4 @@ export interface StockDetail {
8364
website: string;
8465
business_summary: string;
8566
};
86-
created_at: string;
87-
updated_at: string;
88-
is_active: boolean;
8967
}

0 commit comments

Comments
 (0)