feat(webui): integrate i18n into share-settings-sidebar component

This commit is contained in:
yiling
2026-06-27 14:53:09 +08:00
parent 0fd826b973
commit 4475c7bed6
7 changed files with 82 additions and 33 deletions
@@ -63,7 +63,7 @@ export function ShareSettingsSidebar({
const res = await client.api.projects[':projectId'].fields.$get({ const res = await client.api.projects[':projectId'].fields.$get({
param: { projectId: shareLink.projectId }, param: { projectId: shareLink.projectId },
}) })
if (!res.ok) throw new Error('Failed to fetch fields') if (!res.ok) throw new Error(m.failed_fetch_fields())
return await res.json() return await res.json()
}, },
enabled: !!shareLink.projectId, enabled: !!shareLink.projectId,
@@ -76,13 +76,13 @@ export function ShareSettingsSidebar({
param: { shareId: shareLink.id }, param: { shareId: shareLink.id },
json, json,
}) })
if (!res.ok) throw new Error('Failed to update') if (!res.ok) throw new Error(m.failed_update())
return await res.json() return await res.json()
}, },
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['shares', shareLink.projectId] }) queryClient.invalidateQueries({ queryKey: ['shares', shareLink.projectId] })
queryClient.invalidateQueries({ queryKey: ['share', shareLink.id] }) queryClient.invalidateQueries({ queryKey: ['share', shareLink.id] })
toast.success('Settings updated') toast.success(m.settings_updated())
}, },
}) })
@@ -90,7 +90,7 @@ export function ShareSettingsSidebar({
const copyToClipboard = (text: string) => { const copyToClipboard = (text: string) => {
navigator.clipboard.writeText(text) navigator.clipboard.writeText(text)
toast.success('Copied to clipboard') toast.success(m.copied_to_clipboard())
} }
const toggleFieldVisibility = (fieldId: string) => { const toggleFieldVisibility = (fieldId: string) => {
@@ -135,11 +135,11 @@ export function ShareSettingsSidebar({
</div> </div>
<div className="space-y-1"> <div className="space-y-1">
<SidebarAccordionItem title="Security" icon={<Shield className="h-4 w-4" />}> <SidebarAccordionItem title={m.security()} icon={<Shield className="h-4 w-4" />}>
<div className="p-3 space-y-4 pt-0"> <div className="p-3 space-y-4 pt-0">
<div className="space-y-2"> <div className="space-y-2">
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<Label className="text-xs">Password</Label> <Label className="text-xs">{m.password()}</Label>
<Switch <Switch
checked={isPasswordEnabled} checked={isPasswordEnabled}
onCheckedChange={(checked) => { onCheckedChange={(checked) => {
@@ -154,18 +154,18 @@ export function ShareSettingsSidebar({
type="text" type="text"
value={password} value={password}
onChange={(e) => setPassword(e.target.value)} onChange={(e) => setPassword(e.target.value)}
placeholder="Enter password" placeholder={m.enter_password()}
className="text-xs" className="text-xs"
/> />
<Button size="sm" onClick={() => updateShare({ password })}> <Button size="sm" onClick={() => updateShare({ password })}>
Save {m.save()}
</Button> </Button>
</div> </div>
)} )}
</div> </div>
<div className="space-y-2"> <div className="space-y-2">
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<Label className="text-xs">Expiration Date</Label> <Label className="text-xs">{m.expiration_date()}</Label>
<Switch <Switch
checked={isExpireEnabled} checked={isExpireEnabled}
onCheckedChange={(checked) => { onCheckedChange={(checked) => {
@@ -192,7 +192,7 @@ export function ShareSettingsSidebar({
</div> </div>
</div> </div>
</SidebarAccordionItem> </SidebarAccordionItem>
<SidebarAccordionItem title="Appearance" icon={<Palette className="h-4 w-4" />}> <SidebarAccordionItem title={m.appearance()} icon={<Palette className="h-4 w-4" />}>
<div className="p-3 space-y-3 pt-0 flex gap-2"> <div className="p-3 space-y-3 pt-0 flex gap-2">
<Button <Button
variant={viewMode === 'card' ? 'secondary' : 'outline'} variant={viewMode === 'card' ? 'secondary' : 'outline'}
@@ -201,7 +201,7 @@ export function ShareSettingsSidebar({
onClick={() => onViewModeChange('card')} onClick={() => onViewModeChange('card')}
> >
<LayoutGrid className="h-4 w-4" /> <LayoutGrid className="h-4 w-4" />
Grid {m.grid()}
</Button> </Button>
<Button <Button
variant={viewMode === 'list' ? 'secondary' : 'outline'} variant={viewMode === 'list' ? 'secondary' : 'outline'}
@@ -210,11 +210,11 @@ export function ShareSettingsSidebar({
onClick={() => onViewModeChange('list')} onClick={() => onViewModeChange('list')}
> >
<List className="h-4 w-4" /> <List className="h-4 w-4" />
List {m.list()}
</Button> </Button>
</div> </div>
</SidebarAccordionItem> </SidebarAccordionItem>
<SidebarAccordionItem title="Fields" icon={<ListFilter className="h-4 w-4" />}> <SidebarAccordionItem title={m.fields()} icon={<ListFilter className="h-4 w-4" />}>
<div className="p-3 space-y-3 pt-0"> <div className="p-3 space-y-3 pt-0">
{(fields as MetadataFieldInfo[])?.map((field) => ( {(fields as MetadataFieldInfo[])?.map((field) => (
<div key={field.id} className="flex items-center justify-between"> <div key={field.id} className="flex items-center justify-between">
@@ -227,10 +227,10 @@ export function ShareSettingsSidebar({
))} ))}
</div> </div>
</SidebarAccordionItem> </SidebarAccordionItem>
<SidebarAccordionItem title="Sort by" icon={<SortAsc className="h-4 w-4" />}> <SidebarAccordionItem title={m.sort_by()} icon={<SortAsc className="h-4 w-4" />}>
<div className="p-3 space-y-4 pt-0"> <div className="p-3 space-y-4 pt-0">
<div className="space-y-2"> <div className="space-y-2">
<Label className="text-xs text-muted-foreground">Field</Label> <Label className="text-xs text-muted-foreground">{m.field()}</Label>
<Select <Select
value={currentSortField} value={currentSortField}
onValueChange={(val) => { onValueChange={(val) => {
@@ -245,16 +245,16 @@ export function ShareSettingsSidebar({
<SelectValue /> <SelectValue />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
<SelectItem value="index">Custom</SelectItem> <SelectItem value="index">{m.sort_custom()}</SelectItem>
<SelectItem value="name">Name</SelectItem> <SelectItem value="name">{m.sort_name()}</SelectItem>
<SelectItem value="createdAt">Date Created</SelectItem> <SelectItem value="createdAt">{m.sort_date_created()}</SelectItem>
<SelectItem value="size">Size</SelectItem> <SelectItem value="size">{m.sort_size()}</SelectItem>
</SelectContent> </SelectContent>
</Select> </Select>
</div> </div>
<div className="space-y-2"> <div className="space-y-2">
<Label className="text-xs text-muted-foreground">Order</Label> <Label className="text-xs text-muted-foreground">{m.order()}</Label>
<Button <Button
variant="outline" variant="outline"
className="w-full justify-between font-normal text-xs h-9" className="w-full justify-between font-normal text-xs h-9"
@@ -267,19 +267,19 @@ export function ShareSettingsSidebar({
<span> <span>
{currentSortField === 'name' {currentSortField === 'name'
? currentSortOrder === 'asc' ? currentSortOrder === 'asc'
? 'A → Z' ? m.sort_a_to_z()
: 'Z → A' : m.sort_z_to_a()
: currentSortField === 'createdAt' : currentSortField === 'createdAt'
? currentSortOrder === 'asc' ? currentSortOrder === 'asc'
? 'Oldest → Newest' ? m.sort_oldest_to_newest()
: 'Newest → Oldest' : m.sort_newest_to_oldest()
: currentSortField === 'size' : currentSortField === 'size'
? currentSortOrder === 'asc' ? currentSortOrder === 'asc'
? 'Smallest → Largest' ? m.sort_smallest_to_largest()
: 'Largest → Smallest' : m.sort_largest_to_smallest()
: currentSortOrder === 'asc' : currentSortOrder === 'asc'
? 'Ascending' ? m.ascending()
: 'Descending'} : m.descending()}
</span> </span>
<ArrowDownUp className="h-4 w-4 opacity-50" /> <ArrowDownUp className="h-4 w-4 opacity-50" />
</Button> </Button>
@@ -297,14 +297,14 @@ export function ShareSettingsSidebar({
onClick={() => window.open(shareUrl, '_blank')} onClick={() => window.open(shareUrl, '_blank')}
> >
<ExternalLink className="h-4 w-4 mr-2" /> <ExternalLink className="h-4 w-4 mr-2" />
Open Share Link {m.open_share_link()}
</Button> </Button>
<Button <Button
className="w-full justify-center bg-blue-600 hover:bg-blue-700 text-white" className="w-full justify-center bg-blue-600 hover:bg-blue-700 text-white"
onClick={() => copyToClipboard(shareUrl)} onClick={() => copyToClipboard(shareUrl)}
> >
<Copy className="h-4 w-4 mr-2" /> <Copy className="h-4 w-4 mr-2" />
Copy Link {m.copy_link()}
</Button> </Button>
</div> </div>
</div> </div>
+2 -1
View File
@@ -794,5 +794,6 @@
"failed_fetch_folders": "Failed to fetch folders", "failed_fetch_folders": "Failed to fetch folders",
"failed_fetch_files": "Failed to fetch files", "failed_fetch_files": "Failed to fetch files",
"failed_remove": "Failed to remove", "failed_remove": "Failed to remove",
"failed_update": "Failed to update" "failed_update": "Failed to update",
"failed_fetch_fields": "Failed to fetch fields"
} }
+2 -1
View File
@@ -794,5 +794,6 @@
"failed_fetch_folders": "获取文件夹失败", "failed_fetch_folders": "获取文件夹失败",
"failed_fetch_files": "获取文件失败", "failed_fetch_files": "获取文件失败",
"failed_remove": "移除失败", "failed_remove": "移除失败",
"failed_update": "更新失败" "failed_update": "更新失败",
"failed_fetch_fields": "获取字段列表失败"
} }
+1
View File
@@ -742,4 +742,5 @@ export * from "./failed_fetch_folders.js";
export * from "./failed_fetch_files.js"; export * from "./failed_fetch_files.js";
export * from "./failed_remove.js"; export * from "./failed_remove.js";
export * from "./failed_update.js"; export * from "./failed_update.js";
export * from "./failed_fetch_fields.js";
export type LocalizedString = import("../runtime.js").LocalizedString; export type LocalizedString = import("../runtime.js").LocalizedString;
@@ -744,3 +744,4 @@ export * from './failed_fetch_folders.js'
export * from './failed_fetch_files.js' export * from './failed_fetch_files.js'
export * from './failed_remove.js' export * from './failed_remove.js'
export * from './failed_update.js' export * from './failed_update.js'
export * from './failed_fetch_fields.js'
@@ -0,0 +1,16 @@
/**
* | output |
* | --- |
* | "Failed to fetch fields" |
*
* @param {Failed_Fetch_FieldsInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const failed_fetch_fields: ((inputs?: Failed_Fetch_FieldsInputs, options?: {
locale?: "en" | "zh";
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Failed_Fetch_FieldsInputs, {
locale?: "en" | "zh";
}, {}>;
export type LocalizedString = import("../runtime.js").LocalizedString;
export type Failed_Fetch_FieldsInputs = {};
@@ -0,0 +1,29 @@
/* eslint-disable */
import { getLocale, experimentalStaticLocale } from '../runtime.js';
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
/** @typedef {{}} Failed_Fetch_FieldsInputs */
const en_failed_fetch_fields = /** @type {(inputs: Failed_Fetch_FieldsInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`Failed to fetch fields`)
};
const zh_failed_fetch_fields = /** @type {(inputs: Failed_Fetch_FieldsInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`获取字段列表失败`)
};
/**
* | output |
* | --- |
* | "Failed to fetch fields" |
*
* @param {Failed_Fetch_FieldsInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const failed_fetch_fields = /** @type {((inputs?: Failed_Fetch_FieldsInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Failed_Fetch_FieldsInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
if (locale === "en") return en_failed_fetch_fields(inputs)
return zh_failed_fetch_fields(inputs)
});