MCPcopy Create free account
hub / github.com/outerbase/studio / FileHandlerPicker

Function FileHandlerPicker

src/components/filehandler-picker.tsx:62–116  ·  view source on GitHub ↗
({
  value,
  onChange,
}: {
  value?: string;
  onChange: (file: string) => void;
})

Source from the content-addressed store, hash-verified

60}
61
62export default function FileHandlerPicker({
63 value,
64 onChange,
65}: {
66 value?: string;
67 onChange: (file: string) => void;
68}) {
69 const [handler, setHandler] = useState<FileSystemHandle>();
70 const { showDialog } = useCommonDialog();
71
72 useEffect(() => {
73 if (value) {
74 localDb.file_handler.get(value).then((data) => {
75 if (data?.handler) {
76 setHandler(data.handler);
77 }
78 });
79 }
80 }, [value]);
81
82 const onChangeFile = useCallback(() => {
83 try {
84 cleanupFileHandler()
85 .then(openFileHandler)
86 .then(onChange)
87 .catch(() => {
88 showDialog(unsupportFileHandlerDialogContent);
89 });
90 } catch {
91 showDialog(unsupportFileHandlerDialogContent);
92 }
93 }, [onChange, showDialog]);
94
95 if (handler) {
96 return (
97 <div
98 onClick={onChangeFile}
99 className={cn(
100 buttonVariants({ variant: "outline" }),
101 "w-full cursor-pointer justify-start"
102 )}
103 >
104 <LucideFile className="mr-2 h-4 w-4" />
105 {handler.name}
106 </div>
107 );
108 }
109
110 return (
111 <Button onClick={onChangeFile} variant={"outline"}>
112 <LucideFolderClosed className="mr-2 h-4 w-4" />
113 Open File
114 </Button>
115 );
116}

Callers

nothing calls this directly

Calls 3

useCommonDialogFunction · 0.90
cnFunction · 0.90
cleanupFileHandlerFunction · 0.85

Tested by

no test coverage detected