Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/mobile/src/components/ui/ListChoiceRow.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ReactNode } from "react";
import { Platform, View } from "react-native";
import { Platform, View, type PressableProps } from "react-native";
import { useResolveClassNames } from "uniwind";

import { cn } from "../../lib/cn";
Expand All @@ -17,6 +17,8 @@ export function ListChoiceRow(props: {
readonly separated?: boolean;
readonly disabled?: boolean;
readonly onPress: () => void;
/** Lets a wrapping long-press Menu observe the touch. */
readonly onTouchStart?: PressableProps["onTouchStart"];
}) {
const rippleStyle = useResolveClassNames("bg-subtle-strong");
return (
Expand All @@ -27,6 +29,7 @@ export function ListChoiceRow(props: {
accessibilityState={{ checked: props.selected, disabled: Boolean(props.disabled) }}
disabled={props.disabled}
onPress={props.onPress}
onTouchStart={props.onTouchStart}
android_ripple={{ color: rippleStyle.backgroundColor }}
unstable_pressDelay={Platform.OS === "android" ? 50 : undefined}
// Like UIKit and Material lists, only the checkmark or radio marks the selected row.
Expand Down
10 changes: 7 additions & 3 deletions apps/mobile/src/features/home/thread-swipe-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ interface ThreadSwipeableProps {
readonly enableTrackpadSwipe?: boolean;
/** Omitted uses Delete only with the built-in Delete secondary action; otherwise it uses primary. */
readonly fullSwipeAction?: "delete" | "primary";
readonly fullSwipeWidth: number;
/** Initial full-swipe width used until the row's own layout is measured. */
readonly fullSwipeWidth?: number;
/** The list animates item layout; collapse in one step so its transition moves siblings once. */
readonly listAnimatesLayout?: boolean;
readonly onDelete: () => void;
Expand All @@ -262,7 +263,9 @@ export function ThreadSwipeable(props: ThreadSwipeableProps) {
const swipeableRef = useRef<SwipeableMethods | null>(null);
const hasSecondaryAction = props.secondaryAction !== null;
const actionsWidth = swipeActionsWidth(hasSecondaryAction);
const fullSwipeThreshold = Math.max(actionsWidth + 44, props.fullSwipeWidth * 0.58);
const [measuredRowWidth, setMeasuredRowWidth] = useState(0);
const swipeWidth = measuredRowWidth > 0 ? measuredRowWidth : (props.fullSwipeWidth ?? 0);
const fullSwipeThreshold = Math.max(actionsWidth + 44, swipeWidth * 0.58);
const fullSwipeAction =
props.fullSwipeAction ?? (props.secondaryAction === undefined ? "delete" : "primary");
const close = useCallback(() => swipeableRef.current?.close(), []);
Expand All @@ -281,7 +284,7 @@ export function ThreadSwipeable(props: ThreadSwipeableProps) {
const [collapsedInList, setCollapsedInList] = useState(false);
const dismissing = useSharedValue(false);
const rowHeight = useSharedValue(0);
const rowWidth = useSharedValue(props.fullSwipeWidth);
const rowWidth = useSharedValue(props.fullSwipeWidth ?? 0);
const collapse = useSharedValue(0);
const fallbackTranslation = useSharedValue(0);
const actionOpacity = useSharedValue(1);
Expand Down Expand Up @@ -544,6 +547,7 @@ export function ThreadSwipeable(props: ThreadSwipeableProps) {
onLayout={({ nativeEvent: { layout } }) => {
rowHeight.set(layout.height);
setMeasuredRowHeight(layout.height);
setMeasuredRowWidth(layout.width);
rowWidth.set(layout.width);
}}
>
Expand Down
89 changes: 82 additions & 7 deletions apps/mobile/src/features/settings/VoiceModelSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useNavigation } from "@react-navigation/native";
import {
cancelEnvironmentSpeechModelDownload,
installEnvironmentSpeechModel,
removeEnvironmentSpeechModel,
selectEnvironmentSpeechModel,
} from "@t3tools/client-runtime/voice-input";
import {
Expand All @@ -14,17 +15,19 @@ import {
} from "@t3tools/contracts";
import { AsyncResult } from "effect/reactivity";
import { type ReactNode, useEffect, useState } from "react";
import { Platform, Text as NativeText, View } from "react-native";
import { Platform, Pressable, Text as NativeText, View } from "react-native";
import { m } from "../../i18n/messages";

import { SymbolView } from "../../components/ui/AppSymbol";
import { AppText as Text } from "../../components/ui/AppText";
import * as Dialog from "../../components/ui/Dialog";
import { Menu } from "../../components/ui/Menu";
import { ListActionRow } from "../../components/ui/ListActionRow";
import { ListChoiceRow } from "../../components/ui/ListChoiceRow";
import { ListRow } from "../../components/ui/ListRow";
import { Progress } from "../../components/ui/Progress";
import { formatBytes } from "../../lib/formatBytes";
import { ThreadSwipeable } from "../home/thread-swipe-actions";
import { useEnvironmentScope } from "../../state/session";
import {
runSpeech,
Expand Down Expand Up @@ -109,6 +112,25 @@ export function useVoiceModels(environmentId: EnvironmentId, label: string) {
runSpeech(selectEnvironmentSpeechModel(connection, model.id)),
);
},
remove: (model: EnvironmentSpeechModel) => {
if (!ready) return;
Dialog.confirm({
title: gt("Delete {model}?", { model: model.name }),
message: gt(
"{environment} will delete {size} of model files. You can download it again later.",
{
environment: label,
size: formatBytes(model.size),
},
),
confirmText: gt("Delete", { $context: "verb" }),
destructive: true,
onConfirm: () =>
void run(gt("Could not delete the model"), () =>
runSpeech(removeEnvironmentSpeechModel(connection, model.id)),
),
});
},
cancel: (model: EnvironmentSpeechModel) => {
if (!ready) return;
void run(gt("Could not cancel the download"), () =>
Expand Down Expand Up @@ -202,9 +224,16 @@ function ModelStats(props: { readonly model: EnvironmentSpeechModel; readonly la
);
}

function DownloadedGlyph() {
function DownloadedGlyph(props: { readonly label: string; readonly onPress?: () => void }) {
return (
<View className="size-6">
<Pressable
accessibilityRole="button"
accessibilityLabel={props.label}
disabled={!props.onPress}
hitSlop={12}
onPress={props.onPress}
className="size-6"
>
<SymbolView
name="tray.and.arrow.down"
size={Platform.OS === "android" ? 24 : 22}
Expand All @@ -221,7 +250,7 @@ function DownloadedGlyph() {
weight="bold"
/>
</View>
</View>
</Pressable>
);
}

Expand All @@ -235,10 +264,17 @@ export function VoiceModelRow(props: {
const gt = useGT();
const { model, voice, separated } = props;
const meta = <ModelStats model={model} language={props.language} />;
if (model.state === "installed")
return (
if (model.state === "installed") {
const removable = voice.canManage && !voice.busy && !voice.downloading;
const remove = () => voice.remove(model);
const choice = (
<ListChoiceRow
leading={<DownloadedGlyph />}
leading={
<DownloadedGlyph
label={gt("Delete {model}", { model: model.name })}
onPress={removable ? remove : undefined}
/>
}
label={model.name}
description={model.description}
meta={meta}
Expand All @@ -248,6 +284,45 @@ export function VoiceModelRow(props: {
onPress={() => voice.select(model)}
/>
);
if (!removable) return choice;
const row = (
<Menu
actions={[
{
id: "delete",
title: gt("Delete", { $context: "verb" }),
image: "trash",
attributes: { destructive: true },
},
]}
onPressAction={({ nativeEvent }) => {
if (nativeEvent.event === "delete") remove();
}}
shouldOpenOnLongPress
>
{choice}
</Menu>
);
return (
<ThreadSwipeable
backgroundColor="transparent"
fullSwipeAction="primary"
onDelete={remove}
primaryAction={{
accessibilityLabel: gt("Delete {model}", { model: model.name }),
destructive: true,
icon: "trash",
label: gt("Delete", { $context: "verb" }),
onPress: remove,
}}
secondaryAction={null}
threadKey={`speech-model:${model.id}`}
threadTitle={model.name}
>
{() => row}
</ThreadSwipeable>
);
}
const progress = model.downloaded === undefined ? undefined : model.downloaded / model.size;
if (isDownloading(model) || voice.requested === model.id)
return (
Expand Down
7 changes: 6 additions & 1 deletion apps/mobile/src/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -5703,5 +5703,10 @@
"99451a5d2d40440f": "Zurückgezogen von {by}.",
"3ee30a50b70fffab": "Zurückgezogen von {by}: {reason}",
"201490988858b511": "zurückgezogen von {by}",
"46d614fa7b4bf1e5": "Workflow-Ausführungen"
"46d614fa7b4bf1e5": "Workflow-Ausführungen",
"6381c4a2297e37e6": "{model} löschen?",
"00b5905cc4800231": "{environment} löscht {size} an Modelldateien. Du kannst das Modell später erneut herunterladen.",
"c73437a48071f19d": "Löschen",
"51fd61b9c85dec5d": "Das Modell konnte nicht gelöscht werden",
"88fa0730d8c7eab4": "{model} löschen"
}
7 changes: 6 additions & 1 deletion apps/mobile/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5705,5 +5705,10 @@
"99451a5d2d40440f": "Withdrawn by {by}.",
"3ee30a50b70fffab": "Withdrawn by {by}: {reason}",
"201490988858b511": "withdrawn by {by}",
"46d614fa7b4bf1e5": "Workflow runs"
"46d614fa7b4bf1e5": "Workflow runs",
"6381c4a2297e37e6": "Delete {model}?",
"00b5905cc4800231": "{environment} will delete {size} of model files. You can download it again later.",
"c73437a48071f19d": "Delete",
"51fd61b9c85dec5d": "Could not delete the model",
"88fa0730d8c7eab4": "Delete {model}"
}
7 changes: 6 additions & 1 deletion apps/mobile/src/i18n/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -5697,5 +5697,10 @@
"99451a5d2d40440f": "Retirada por {by}.",
"3ee30a50b70fffab": "Retirada por {by}: {reason}",
"201490988858b511": "retirada por {by}",
"46d614fa7b4bf1e5": "Ejecuciones de flujos de trabajo"
"46d614fa7b4bf1e5": "Ejecuciones de flujos de trabajo",
"6381c4a2297e37e6": "¿Eliminar {model}?",
"00b5905cc4800231": "{environment} eliminará {size} de archivos del modelo. Puedes volver a descargarlo más tarde.",
"c73437a48071f19d": "Eliminar",
"51fd61b9c85dec5d": "No se pudo eliminar el modelo",
"88fa0730d8c7eab4": "Eliminar {model}"
}
7 changes: 6 additions & 1 deletion apps/mobile/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -5697,5 +5697,10 @@
"99451a5d2d40440f": "Retirée par {by}.",
"3ee30a50b70fffab": "Retirée par {by} : {reason}",
"201490988858b511": "retirée par {by}",
"46d614fa7b4bf1e5": "Exécutions de workflow"
"46d614fa7b4bf1e5": "Exécutions de workflow",
"6381c4a2297e37e6": "Supprimer {model} ?",
"00b5905cc4800231": "{environment} va supprimer {size} de fichiers de modèle. Vous pourrez le télécharger à nouveau plus tard.",
"c73437a48071f19d": "Supprimer",
"51fd61b9c85dec5d": "Impossible de supprimer le modèle",
"88fa0730d8c7eab4": "Supprimer {model}"
}
7 changes: 6 additions & 1 deletion apps/mobile/src/i18n/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -5674,5 +5674,10 @@
"99451a5d2d40440f": "{by} が取り下げました。",
"3ee30a50b70fffab": "{by} が取り下げました: {reason}",
"201490988858b511": "{by} が取り下げ",
"46d614fa7b4bf1e5": "ワークフローの実行"
"46d614fa7b4bf1e5": "ワークフローの実行",
"6381c4a2297e37e6": "{model} を削除しますか?",
"00b5905cc4800231": "{environment} は {size} のモデルファイルを削除します。後で再度ダウンロードできます。",
"c73437a48071f19d": "削除",
"51fd61b9c85dec5d": "モデルを削除できませんでした",
"88fa0730d8c7eab4": "{model} を削除"
}
7 changes: 6 additions & 1 deletion apps/mobile/src/i18n/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -5681,5 +5681,10 @@
"99451a5d2d40440f": "{by}에서 철회했습니다.",
"3ee30a50b70fffab": "{by}에서 철회했습니다: {reason}",
"201490988858b511": "{by}에서 철회함",
"46d614fa7b4bf1e5": "워크플로 실행"
"46d614fa7b4bf1e5": "워크플로 실행",
"6381c4a2297e37e6": "{model}을(를) 삭제할까요?",
"00b5905cc4800231": "{environment}에서 모델 파일 {size}를 삭제합니다. 나중에 다시 다운로드할 수 있습니다.",
"c73437a48071f19d": "삭제",
"51fd61b9c85dec5d": "모델을 삭제할 수 없습니다",
"88fa0730d8c7eab4": "{model} 삭제"
}
7 changes: 6 additions & 1 deletion apps/mobile/src/i18n/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -5697,5 +5697,10 @@
"99451a5d2d40440f": "Retirada por {by}.",
"3ee30a50b70fffab": "Retirada por {by}: {reason}",
"201490988858b511": "retirada por {by}",
"46d614fa7b4bf1e5": "Execuções de workflow"
"46d614fa7b4bf1e5": "Execuções de workflow",
"6381c4a2297e37e6": "Excluir {model}?",
"00b5905cc4800231": "{environment} vai excluir {size} de arquivos de modelo. Você pode baixá-lo novamente mais tarde.",
"c73437a48071f19d": "Excluir",
"51fd61b9c85dec5d": "Não foi possível excluir o modelo",
"88fa0730d8c7eab4": "Excluir {model}"
}
7 changes: 6 additions & 1 deletion apps/mobile/src/i18n/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -5777,5 +5777,10 @@
"99451a5d2d40440f": "Отозван: {by}.",
"3ee30a50b70fffab": "Отозван ({by}): {reason}",
"201490988858b511": "отозван: {by}",
"46d614fa7b4bf1e5": "Запуски воркфлоу"
"46d614fa7b4bf1e5": "Запуски воркфлоу",
"6381c4a2297e37e6": "Удалить {model}?",
"00b5905cc4800231": "{environment} удалит {size} файлов модели. Вы сможете скачать её снова позже.",
"c73437a48071f19d": "Удалить",
"51fd61b9c85dec5d": "Не удалось удалить модель",
"88fa0730d8c7eab4": "Удалить {model}"
}
7 changes: 6 additions & 1 deletion apps/mobile/src/i18n/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -5703,5 +5703,10 @@
"99451a5d2d40440f": "Återkallad av {by}.",
"3ee30a50b70fffab": "Återkallad av {by}: {reason}",
"201490988858b511": "återkallad av {by}",
"46d614fa7b4bf1e5": "Arbetsflödeskörningar"
"46d614fa7b4bf1e5": "Arbetsflödeskörningar",
"6381c4a2297e37e6": "Ta bort {model}?",
"00b5905cc4800231": "{environment} tar bort {size} modellfiler. Du kan ladda ned den igen senare.",
"c73437a48071f19d": "Ta bort",
"51fd61b9c85dec5d": "Kunde inte ta bort modellen",
"88fa0730d8c7eab4": "Ta bort {model}"
}
7 changes: 6 additions & 1 deletion apps/mobile/src/i18n/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -5684,5 +5684,10 @@
"99451a5d2d40440f": "已由 {by} 撤回。",
"3ee30a50b70fffab": "已由 {by} 撤回:{reason}",
"201490988858b511": "已由 {by} 撤回",
"46d614fa7b4bf1e5": "工作流运行"
"46d614fa7b4bf1e5": "工作流运行",
"6381c4a2297e37e6": "删除 {model}?",
"00b5905cc4800231": "{environment} 将删除 {size} 的模型文件。之后可以重新下载。",
"c73437a48071f19d": "删除",
"51fd61b9c85dec5d": "无法删除模型",
"88fa0730d8c7eab4": "删除 {model}"
}
Loading