Enable toggling waypoint sending characters
This commit is contained in:
@@ -11,7 +11,8 @@ import {
|
||||
} from '@/components/ui/breadcrumb';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { toast } from '@/hooks/use-toast';
|
||||
import { StartESILogin, ESILoggedIn, ListCharacters } from 'wailsjs/go/main/App';
|
||||
import { StartESILogin, ESILoggedIn, ListCharacters, ToggleCharacterWaypointEnabled } from 'wailsjs/go/main/App';
|
||||
import { main } from 'wailsjs/go/models';
|
||||
|
||||
interface HeaderProps {
|
||||
title: string;
|
||||
@@ -21,16 +22,14 @@ interface HeaderProps {
|
||||
}>;
|
||||
}
|
||||
|
||||
interface CharacterInfo { character_id: number; character_name: string }
|
||||
|
||||
export const Header = ({ title, breadcrumbs = [] }: HeaderProps) => {
|
||||
const navigate = useNavigate();
|
||||
const [chars, setChars] = useState<CharacterInfo[]>([]);
|
||||
const [chars, setChars] = useState<main.CharacterInfo[]>([]);
|
||||
|
||||
const refreshState = async () => {
|
||||
try {
|
||||
const list = await ListCharacters();
|
||||
setChars((list as any[]).map((c: any) => ({ character_id: c.character_id, character_name: c.character_name })));
|
||||
setChars(list);
|
||||
} catch { }
|
||||
};
|
||||
|
||||
@@ -55,6 +54,17 @@ export const Header = ({ title, breadcrumbs = [] }: HeaderProps) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleCharacterClick = async (character: main.CharacterInfo) => {
|
||||
try {
|
||||
await ToggleCharacterWaypointEnabled(character.character_id);
|
||||
await refreshState();
|
||||
const newStatus = character.waypoint_enabled ? 'disabled' : 'enabled';
|
||||
toast({ title: 'Waypoint Status', description: `${character.character_name} waypoints ${newStatus}` });
|
||||
} catch (e: any) {
|
||||
toast({ title: 'Toggle failed', description: String(e), variant: 'destructive' });
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex-shrink-0 py-4 px-4 border-b border-purple-500/20">
|
||||
{breadcrumbs.length > 0 && (
|
||||
@@ -89,9 +99,24 @@ export const Header = ({ title, breadcrumbs = [] }: HeaderProps) => {
|
||||
<h1 className="text-2xl font-bold text-white">{title}</h1>
|
||||
<div className="flex items-center gap-3">
|
||||
{chars.length > 0 && (
|
||||
<div className="flex flex-wrap gap-2 max-w-[50vw] justify-end">
|
||||
<div
|
||||
className="grid gap-1 flex-1 justify-end"
|
||||
style={{
|
||||
gridTemplateColumns: `repeat(${Math.ceil(chars.length / 2)}, 1fr)`,
|
||||
gridTemplateRows: 'repeat(2, auto)'
|
||||
}}
|
||||
>
|
||||
{chars.map((c) => (
|
||||
<span key={c.character_id} className="px-2 py-1 rounded-full bg-purple-500/20 text-purple-200 border border-purple-400/40 text-xs whitespace-nowrap">
|
||||
<span
|
||||
key={c.character_id}
|
||||
onClick={() => handleCharacterClick(c)}
|
||||
className={`px-3 py-1 text-xs cursor-pointer transition-colors text-center overflow-hidden text-ellipsis ${
|
||||
c.waypoint_enabled
|
||||
? 'bg-purple-500/20 text-purple-200 border border-purple-400/40 hover:bg-purple-500/30'
|
||||
: 'bg-gray-500/20 text-gray-400 border border-gray-400/40 hover:bg-gray-500/30'
|
||||
}`}
|
||||
title={`Click to ${c.waypoint_enabled ? 'disable' : 'enable'} waypoints for ${c.character_name}`}
|
||||
>
|
||||
{c.character_name}
|
||||
</span>
|
||||
))}
|
||||
|
Reference in New Issue
Block a user