Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): recommend function template config with templateid #1947

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useEffect, useMemo, useState } from "react";
import { Controller, useForm } from "react-hook-form";
import { useNavigate } from "react-router-dom";
import {
Expand Down Expand Up @@ -31,7 +31,10 @@ import useFunctionStore from "../../../store";
import { TFunctionTemplate, TMethod } from "@/apis/typing";
import FunctionTemplate from "@/pages/functionTemplate";
import TemplateCard from "@/pages/functionTemplate/Mods/TemplateCard";
import { useGetRecommendFunctionTemplatesQuery } from "@/pages/functionTemplate/service";
import {
useGetFunctionTemplatesQuery,
useGetRecommendFunctionTemplatesQuery,
} from "@/pages/functionTemplate/service";
import useTemplateStore from "@/pages/functionTemplate/store";
import useGlobalStore from "@/pages/globalStore";

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

useEffect(() => {
const searchParams = new URLSearchParams(window.location.search);
const templateId = searchParams.get("templateId");
if (!templateId) return;
localStorage.setItem("templateId", templateId);
}, []);

const defaultValues = {
name: functionItem?.name || "",
description: functionItem?.desc || "",
Expand Down Expand Up @@ -100,6 +110,31 @@ const CreateModal = (props: {
enabled: !isOpen && !isEdit,
},
);
const searchedTemplateList = useGetFunctionTemplatesQuery(
{
page: 1,
pageSize: 3,
keyword: localStorage.getItem("templateid") || "",
type: "default",
newfish-cmyk marked this conversation as resolved.
Show resolved Hide resolved
asc: 1,
sort: null,
},
{
enabled: !!localStorage.getItem("templateid") && !isEdit,
},
);

const recommendedList = useMemo(
() => InitialTemplateList.data?.data.list || [],
[InitialTemplateList],
);
const searchedList = useMemo(
() => searchedTemplateList.data?.data.list || [],
[searchedTemplateList],
);
const showedList = useMemo(() => {
return [...searchedList, ...recommendedList].slice(0, 3);
}, [searchedList, recommendedList]);

const onSubmit = async (data: any) => {
let res: any = {};
Expand Down Expand Up @@ -226,7 +261,6 @@ const CreateModal = (props: {
/>
</div>
</FormControl>

<Button
type="submit"
onClick={handleSubmit(onSubmit)}
Expand All @@ -246,7 +280,7 @@ const CreateModal = (props: {
{t("Template.Recommended")}
</div>
<div className="mb-11 flex w-full">
{InitialTemplateList.data?.data.list.map((item: TFunctionTemplate) => (
{showedList.map((item: TFunctionTemplate) => (
<section
className="h-28 w-1/3 px-1.5 py-1"
key={item._id}
Expand Down
Loading