mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-06-17 19:30:27 +01:00
feat(quick-connect): add a paste button to the authorize code input
Codes often arrive over SMS/another app; add a "Paste code" button under the PIN input that reads the clipboard (expo-clipboard, probed optionally) and keeps the 6 digits.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { Feather } from "@expo/vector-icons";
|
||||
import {
|
||||
BottomSheetBackdrop,
|
||||
type BottomSheetBackdropProps,
|
||||
@@ -5,11 +6,13 @@ import {
|
||||
BottomSheetView,
|
||||
} from "@gorhom/bottom-sheet";
|
||||
import { getQuickConnectApi } from "@jellyfin/sdk/lib/utils/api";
|
||||
import { requireOptionalNativeModule } from "expo-modules-core";
|
||||
import { useAtom } from "jotai";
|
||||
import type React from "react";
|
||||
import { useCallback, useMemo, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Alert, Platform, View, type ViewProps } from "react-native";
|
||||
import { Pressable } from "react-native-gesture-handler";
|
||||
import { useHaptic } from "@/hooks/useHaptic";
|
||||
import { apiAtom, userAtom } from "@/providers/JellyfinProvider";
|
||||
import { Button } from "../Button";
|
||||
@@ -79,6 +82,15 @@ export const QuickConnect: React.FC<Props> = ({ ...props }) => {
|
||||
}
|
||||
}, [api, user, quickConnectCode]);
|
||||
|
||||
const pasteCode = useCallback(async () => {
|
||||
// Builds without the expo-clipboard native module: probe first (no-op).
|
||||
if (!requireOptionalNativeModule("ExpoClipboard")) return;
|
||||
const Clipboard = await import("expo-clipboard");
|
||||
const text = await Clipboard.getStringAsync();
|
||||
const digits = (text || "").replace(/\D/g, "").slice(0, 6);
|
||||
if (digits) setQuickConnectCode(digits);
|
||||
}, []);
|
||||
|
||||
if (isTv) return null;
|
||||
|
||||
return (
|
||||
@@ -130,6 +142,15 @@ export const QuickConnect: React.FC<Props> = ({ ...props }) => {
|
||||
style={{ paddingHorizontal: 16 }}
|
||||
autoFocus
|
||||
/>
|
||||
<Pressable
|
||||
onPress={pasteCode}
|
||||
className='flex-row items-center justify-center self-center'
|
||||
>
|
||||
<Feather name='clipboard' size={15} color='#a3a3a3' />
|
||||
<Text className='text-neutral-400 ml-2'>
|
||||
{t("home.settings.quick_connect.paste_code")}
|
||||
</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
</View>
|
||||
<Button
|
||||
|
||||
Reference in New Issue
Block a user