UNPKG

@websolutespa/payload-plugin-bowl-llm

Version:

LLM plugin for Bowl PayloadCms plugin

71 lines (70 loc) 2.47 kB
'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 { LlmLinksApp } from './LlmLinksApp'; export const LlmLinksClient_ = ()=>{ const { t } = useTranslation(); const { config } = useConfig(); const { routes, serverURL } = config; const locale = useLocale(); const [apps, setApps] = useState([]); const [app, setApp] = useState(); const routeResolver = getRouteResolver(config); // fetch apps useEffect(()=>{ const fetchApps = ()=>{ const url = routeResolver.api(`/llmApp?pagination=false&locale=${locale}`); fetch(url).then((response)=>response.json()).then((apps)=>{ setApps(apps); if (apps && apps.length === 1) { setApp(apps[0]); } }); }; fetchApps(); }, [ locale, routes.api, serverURL ]); 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), value: app?.id }) }) }), app && /*#__PURE__*/ _jsx(LlmLinksApp, { app: app }) ] }); }; export const LlmLinksClient = /*#__PURE__*/ React.memo(LlmLinksClient_); //# sourceMappingURL=LlmLinksClient.js.map