Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5a30f45

Browse files
committed
fix: fix types
1 parent9548678 commit5a30f45

File tree

1 file changed

+35
-31
lines changed

1 file changed

+35
-31
lines changed

‎site/src/pages/TemplatePage/TemplateEmbedPage/TemplateEmbedPageExperimental.tsx

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,34 @@ import Radio from "@mui/material/Radio";
66
importRadioGroupfrom"@mui/material/RadioGroup";
77
import{API}from"api/api";
88
import{DetailedError}from"api/errors";
9-
importtype{
10-
DynamicParametersRequest,
11-
DynamicParametersResponse,
12-
PreviewParameter,
13-
Template
9+
importtype{
10+
DynamicParametersRequest,
11+
DynamicParametersResponse,
12+
PreviewParameter,
13+
Template
1414
}from"api/typesGenerated";
1515
import{FormSection,VerticalForm}from"components/Form/Form";
1616
import{Loader}from"components/Loader/Loader";
1717
import{useClipboard}from"hooks/useClipboard";
1818
import{DynamicParameter}from"modules/workspaces/DynamicParameter/DynamicParameter";
1919
import{useTemplateLayoutContext}from"pages/TemplatePage/TemplateLayout";
2020
import{typeFC,useCallback,useEffect,useRef,useState}from"react";
21+
importReactfrom"react";
2122
import{Helmet}from"react-helmet-async";
2223
import{useQuery}from"react-query";
2324
import{useSearchParams}from"react-router-dom";
2425
import{pageTitle}from"utils/page";
25-
import{getAutofillParameters}from"utils/richParameters";
26+
import{getAutofillParameters,typeAutofillBuildParameterasImportedAutofillBuildParameter}from"utils/richParameters";
2627

2728
typeButtonValues=Record<string,string>;
2829

30+
// Use the imported type instead of redefining it
31+
typeAutofillBuildParameter=ImportedAutofillBuildParameter;
32+
2933
constTemplateEmbedPageExperimental:FC=()=>{
3034
const{ template}=useTemplateLayoutContext();
3135
const[searchParams]=useSearchParams();
32-
36+
3337
return(
3438
<>
3539
<Helmet>
@@ -45,7 +49,7 @@ interface TemplateEmbedPageViewProps {
4549
searchParams:URLSearchParams;
4650
}
4751

48-
constTemplateEmbedPageView:FC<TemplateEmbedPageViewProps>=({
52+
constTemplateEmbedPageView:FC<TemplateEmbedPageViewProps>=({
4953
template,
5054
searchParams
5155
})=>{
@@ -54,7 +58,7 @@ const TemplateEmbedPageView: FC<TemplateEmbedPageViewProps> = ({
5458
constws=useRef<WebSocket|null>(null);
5559
const[wsError,setWsError]=useState<Error|null>(null);
5660
const[buttonValues,setButtonValues]=useState<ButtonValues|undefined>();
57-
61+
5862
// Get the current user
5963
const{data:me}=useQuery({
6064
queryKey:["me"],
@@ -136,45 +140,45 @@ const TemplateEmbedPageView: FC<TemplateEmbedPageViewProps> = ({
136140
constinitValues:ButtonValues={
137141
mode,
138142
};
139-
143+
140144
// Filter only parameters used for workspace creation
141145
constworkspaceParams=currentResponse.parameters.filter(param=>!param.ephemeral);
142-
146+
143147
// Apply autofill parameters from URL if available
144148
for(constparameterofworkspaceParams){
145149
constautofillParam=autofillParameters.find(p=>p.name===parameter.name);
146-
150+
147151
if(autofillParam){
148152
// Use the value from URL parameters
149153
initValues[`param.${parameter.name}`]=autofillParam.value;
150154
}else{
151155
// Use the default or current value from the parameter
152-
constparamValue=parameter.value.valid
153-
?parameter.value.value
156+
constparamValue=parameter.value.valid
157+
?parameter.value.value
154158
:(parameter.default_value.valid ?parameter.default_value.value :"");
155-
159+
156160
initValues[`param.${parameter.name}`]=paramValue;
157161
}
158162
}
159-
163+
160164
setButtonValues(initValues);
161-
165+
162166
// Send initial message to get updated parameters based on autofill values
163167
if(workspaceParams.length>0){
164168
constparamInputs:Record<string,string>={};
165-
169+
166170
for(constparamofworkspaceParams){
167171
constautofillParam=autofillParameters.find(p=>p.name===param.name);
168-
172+
169173
if(autofillParam){
170174
paramInputs[param.name]=autofillParam.value;
171175
}else{
172-
paramInputs[param.name]=param.value.valid
173-
?param.value.value
176+
paramInputs[param.name]=param.value.valid
177+
?param.value.value
174178
:(param.default_value.valid ?param.default_value.value :"");
175179
}
176180
}
177-
181+
178182
sendMessage(paramInputs);
179183
}
180184
}
@@ -240,7 +244,7 @@ const TemplateEmbedPageView: FC<TemplateEmbedPageViewProps> = ({
240244
</FormSection>
241245

242246
{currentResponse?.parameters&&(
243-
<ParametersList
247+
<ParametersList
244248
parameters={currentResponse.parameters}
245249
buttonValues={buttonValues||{}}
246250
setButtonValues={setButtonValues}
@@ -251,7 +255,7 @@ const TemplateEmbedPageView: FC<TemplateEmbedPageViewProps> = ({
251255
</VerticalForm>
252256
</div>
253257

254-
<ButtonPreview
258+
<ButtonPreview
255259
template={template}
256260
buttonValues={buttonValues}
257261
/>
@@ -262,9 +266,9 @@ const TemplateEmbedPageView: FC<TemplateEmbedPageViewProps> = ({
262266
};
263267

264268
interfaceParametersListProps{
265-
parameters:PreviewParameter[];
269+
parameters:readonlyPreviewParameter[];
266270
buttonValues:ButtonValues;
267-
setButtonValues:(values:ButtonValues|((prev:ButtonValues)=>ButtonValues))=>void;
271+
setButtonValues:React.Dispatch<React.SetStateAction<ButtonValues|undefined>>;
268272
sendMessage:(values:Record<string,string>)=>void;
269273
autofillParameters:AutofillBuildParameter[];
270274
}
@@ -278,7 +282,7 @@ const ParametersList: FC<ParametersListProps> = ({
278282
})=>{
279283
// Filter parameters to only include those used for workspace creation
280284
constworkspaceParameters=parameters.filter(param=>!param.ephemeral);
281-
285+
282286
if(workspaceParameters.length===0){
283287
returnnull;
284288
}
@@ -287,10 +291,10 @@ const ParametersList: FC<ParametersListProps> = ({
287291
consthandleParameterChange=(paramName:string,value:string)=>{
288292
// Update button values
289293
setButtonValues((prev)=>({
290-
...prev,
294+
...prev||{},
291295
[`param.${paramName}`]:value,
292296
}));
293-
297+
294298
// Send updated parameters to the server
295299
constparamValues:Record<string,string>={};
296300
for(constparamofworkspaceParameters){
@@ -309,7 +313,7 @@ const ParametersList: FC<ParametersListProps> = ({
309313
{workspaceParameters.map((parameter)=>{
310314
constautofillParam=autofillParameters.find(p=>p.name===parameter.name);
311315
constisAutofilled=!!autofillParam;
312-
316+
313317
return(
314318
<DynamicParameter
315319
key={parameter.name}
@@ -402,4 +406,4 @@ function getClipboardCopyContent(
402406

403407
// Function is now imported from utils/richParameters.ts
404408

405-
exportdefaultTemplateEmbedPageExperimental;
409+
exportdefaultTemplateEmbedPageExperimental;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp