okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-split-int' into f-split-fitfa6367a98

main
1.3 KiB21 linesraw
1import { useEffect, useState } from 'react';
2import { tr } from '../lib/i18n';
3import { useFolderPrompt } from '../lib/folder-pick';
4import { Btn, Dialog } from './ui';
5
6/** The fallback for a system without a folder chooser: say so in plain words and take the folder's path as text. */
7export function FolderPathDialog() {
8  const prompt = useFolderPrompt();
9  const [path, setPath] = useState('');
10  useEffect(() => { if (prompt) setPath(''); }, [prompt]);
11  const submit = () => { const text = path.trim(); if (text) prompt?.resolve(text); };
12  return <Dialog open={!!prompt} compact title={tr("Type the folder path")} onClose={() => prompt?.resolve(null)}
13    actions={<><Btn onClick={() => prompt?.resolve(null)}>{tr("Cancel")}</Btn><Btn variant="primary" disabled={!path.trim()} onClick={submit}>{tr("Use this folder")}</Btn></>}>
14    <form className="stack" onSubmit={event => { event.preventDefault(); submit(); }}>
15      <p className="small" role="status">{tr(prompt?.message ?? '')}</p>
16      <label className="input-field"><span>{tr("Folder path")}</span>
17        <input className="st-input" autoFocus value={path} onChange={event => setPath(event.target.value)} placeholder={tr("/home/you/Documents")} spellCheck={false} aria-label={tr("Folder path")}/>
18      </label>
19    </form>
20  </Dialog>;
21}