@isthatuzii/create-nano-app
Version:
Desktop application scaffolding tool for the Nano Framework
77 lines (64 loc) • 2.02 kB
text/typescript
import type { Accessor, Setter } from "solid-js";
import { invoke } from "../../api/api";
interface GreetingState {
name: string;
greeting: string | null;
loading: boolean;
error: string | null;
}
interface GreetingPanelFunctions {
sendGreeting: () => Promise<void>;
setName: (name: string) => void;
initialize: () => void;
}
export const createGreetingPanelFunctions = (
state: Accessor<GreetingState>,
setState: Setter<GreetingState>,
_props: Record<string, any>,
_api: any
): GreetingPanelFunctions => {
const sendGreeting = async (): Promise<void> => {
if (!state().name.trim()) {
setState(prev => ({ ...prev, error: "Please enter a name" }));
return;
}
setState(prev => ({ ...prev, loading: true, error: null }));
try {
console.log('Attempting to call greet function with name:', state().name);
// Use the direct invoke system for nano functions
const result = await invoke<string>("greet", { name: state().name });
console.log('Greet function result:', result);
setState(prev => ({
...prev,
greeting: result,
loading: false
}));
} catch (error: any) {
console.error('Greeting error details:', {
error: error,
message: error.message,
stack: error.stack
});
// Check if it's a network/server issue
const errorMessage = error.message.includes('File not found')
? 'Server not available. Please make sure the Nano server is running.'
: error.message;
setState(prev => ({
...prev,
error: errorMessage,
loading: false
}));
}
};
const setName = (name: string): void => {
setState(prev => ({ ...prev, name }));
};
const initialize = (): void => {
console.log("👋 Greeting panel initialized");
};
return {
sendGreeting,
setName,
initialize
};
};