Skip to content

Commit f70a7be

Browse files
authored
feat(web): recommend function template config with templateid (#1947)
* feat(web): recommend function template config with templateid
1 parent 9743063 commit f70a7be

File tree

1 file changed

+38
-4
lines changed
  • web/src/pages/app/functions/mods/FunctionPanel/CreateModal

1 file changed

+38
-4
lines changed

web/src/pages/app/functions/mods/FunctionPanel/CreateModal/index.tsx

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from "react";
1+
import React, { useEffect, useMemo, useState } from "react";
22
import { Controller, useForm } from "react-hook-form";
33
import { useNavigate } from "react-router-dom";
44
import {
@@ -31,7 +31,10 @@ import useFunctionStore from "../../../store";
3131
import { TFunctionTemplate, TMethod } from "@/apis/typing";
3232
import FunctionTemplate from "@/pages/functionTemplate";
3333
import TemplateCard from "@/pages/functionTemplate/Mods/TemplateCard";
34-
import { useGetRecommendFunctionTemplatesQuery } from "@/pages/functionTemplate/service";
34+
import {
35+
useGetFunctionTemplatesQuery,
36+
useGetRecommendFunctionTemplatesQuery,
37+
} from "@/pages/functionTemplate/service";
3538
import useTemplateStore from "@/pages/functionTemplate/store";
3639
import useGlobalStore from "@/pages/globalStore";
3740

@@ -54,6 +57,13 @@ const CreateModal = (props: {
5457
useFunctionStore();
5558
const { setShowTemplateItem } = useTemplateStore();
5659

60+
useEffect(() => {
61+
const searchParams = new URLSearchParams(window.location.search);
62+
const templateId = searchParams.get("templateId");
63+
if (!templateId) return;
64+
localStorage.setItem("templateId", templateId);
65+
}, []);
66+
5767
const defaultValues = {
5868
name: functionItem?.name || "",
5969
description: functionItem?.desc || "",
@@ -100,6 +110,31 @@ const CreateModal = (props: {
100110
enabled: !isOpen && !isEdit,
101111
},
102112
);
113+
const searchedTemplateList = useGetFunctionTemplatesQuery(
114+
{
115+
page: 1,
116+
pageSize: 3,
117+
keyword: localStorage.getItem("templateId") || "",
118+
type: "default",
119+
asc: 1,
120+
sort: null,
121+
},
122+
{
123+
enabled: !!localStorage.getItem("templateId") && !isEdit,
124+
},
125+
);
126+
127+
const recommendedList = useMemo(
128+
() => InitialTemplateList.data?.data.list || [],
129+
[InitialTemplateList],
130+
);
131+
const searchedList = useMemo(
132+
() => searchedTemplateList.data?.data.list || [],
133+
[searchedTemplateList],
134+
);
135+
const showedList = useMemo(() => {
136+
return [...searchedList, ...recommendedList].slice(0, 3);
137+
}, [searchedList, recommendedList]);
103138

104139
const onSubmit = async (data: any) => {
105140
let res: any = {};
@@ -226,7 +261,6 @@ const CreateModal = (props: {
226261
/>
227262
</div>
228263
</FormControl>
229-
230264
<Button
231265
type="submit"
232266
onClick={handleSubmit(onSubmit)}
@@ -246,7 +280,7 @@ const CreateModal = (props: {
246280
{t("Template.Recommended")}
247281
</div>
248282
<div className="mb-11 flex w-full">
249-
{InitialTemplateList.data?.data.list.map((item: TFunctionTemplate) => (
283+
{showedList.map((item: TFunctionTemplate) => (
250284
<section
251285
className="h-28 w-1/3 px-1.5 py-1"
252286
key={item._id}

0 commit comments

Comments
 (0)