feat(SearchDialog): add shift-click functionality to set system destination

This commit is contained in:
2025-08-11 22:36:07 +02:00
parent dad6d79740
commit 2d6af8bfa9

View File

@@ -3,7 +3,8 @@ import { useNavigate } from 'react-router-dom';
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import { Input } from '@/components/ui/input';
import { AhoCorasick } from '@/lib/aho';
import { ListSystemsWithRegions } from 'wailsjs/go/main/App';
import { ListSystemsWithRegions, SetDestinationForAll, ListCharacters, StartESILogin } from 'wailsjs/go/main/App';
import { toast } from '@/hooks/use-toast';
interface SearchResult {
system: string;
@@ -80,6 +81,39 @@ export const SearchDialog: React.FC = () => {
navigate(`/regions/${encodeURIComponent(r.region)}?focus=${encodeURIComponent(r.system)}`);
};
const ensureAnyLoggedIn = async (): Promise<boolean> => {
try {
const list = await ListCharacters();
if (Array.isArray(list) && list.length > 0) return true;
await StartESILogin();
toast({ title: 'EVE Login', description: 'Complete login in your browser, then retry.' });
return false;
} catch (e: any) {
await StartESILogin();
toast({ title: 'EVE Login', description: 'Complete login in your browser, then retry.', variant: 'destructive' });
return false;
}
};
const handleResultClick = async (e: React.MouseEvent, r: SearchResult) => {
if (e.shiftKey) {
e.preventDefault();
e.stopPropagation();
try {
if (!(await ensureAnyLoggedIn())) return;
await SetDestinationForAll(r.system, true, false);
toast({ title: 'Destination set', description: r.system });
} catch (err: any) {
toast({ title: 'Failed to set destination', description: String(err), variant: 'destructive' });
} finally {
setOpen(false);
setQuery('');
}
return;
}
onSelect(r);
};
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogContent className="sm:max-w-lg bg-slate-900/95 border border-purple-500/40 text-white">
@@ -102,7 +136,8 @@ export const SearchDialog: React.FC = () => {
<button
key={`${r.region}-${r.system}-${idx}`}
className="w-full text-left p-3 hover:bg-purple-500/20"
onClick={() => onSelect(r)}
onClick={(e) => handleResultClick(e, r)}
title="Click to open, Shift+Click to set destination"
>
<div className="text-sm font-medium">{r.system}</div>
<div className="text-xs text-slate-300">{r.region}</div>