@websolutespa/payload-plugin-bowl-llm
Version:
LLM plugin for Bowl PayloadCms plugin
62 lines (61 loc) • 2.2 kB
JavaScript
'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Form, Gutter, SelectInput, useConfig, useLocale, useTranslation } from '@payloadcms/ui';
import { getRouteResolver } from '@websolutespa/payload-utils';
import React, { useEffect, useMemo, useState } from 'react';
import './Llm.scss';
import { LlmTestApp } from './LlmTestApp';
export const LlmTestClient_ = ()=>{
const { t } = useTranslation();
const { config } = useConfig();
const routeResolver = getRouteResolver(config);
const locale = useLocale();
const [apps, setApps] = useState([]);
const [app, setApp] = useState();
// fetch apps
useEffect(()=>{
const fetchApps = ()=>{
const url = routeResolver.api(`/llmApp?pagination=false&locale=${locale}`);
fetch(url).then((response)=>response.json()).then((apps)=>setApps(apps));
};
fetchApps();
}, [
locale
]);
const selectOptions = useMemo(()=>{
return apps.map((x)=>({
label: x.name,
value: x.id
}));
}, [
apps
]);
const onSelectDidChange = (value)=>{
const app = apps.find((x)=>x.id === value);
setApp(app);
// console.log('onSelectDidChange', app);
};
return /*#__PURE__*/ _jsxs(Gutter, {
className: "llm__container",
children: [
/*#__PURE__*/ _jsx("div", {
className: "llm__app",
children: /*#__PURE__*/ _jsx(Form, {
className: "llm__form",
children: /*#__PURE__*/ _jsx(SelectInput, {
label: t('general:selectApp'),
name: "select",
path: "select",
options: selectOptions,
onChange: (option)=>Array.isArray(option) ? null : onSelectDidChange(option.value)
})
})
}),
app && /*#__PURE__*/ _jsx(LlmTestApp, {
app: app
})
]
});
};
export const LlmTestClient = /*#__PURE__*/ React.memo(LlmTestClient_);
//# sourceMappingURL=LlmTestClient.js.map