From 7f16d4d1a023d63a6790895101edf2034a6dfbec Mon Sep 17 00:00:00 2001
From: heheer <71265218+newfish-cmyk@users.noreply.github.com>
Date: Tue, 25 Jul 2023 11:26:33 +0800
Subject: [PATCH] refactor(web): optimize create function & function template
component (#1416)
* refactor(web): optimize create function component
* refactor(web): adjust function template files
* fix(web): fix frequent avatar flickering
* fix(web): fix billing icon & app list loading
---
web/src/components/CommonIcon/index.tsx | 8 +-
web/src/constants/index.ts | 8 +
web/src/layouts/Header/index.tsx | 234 ++++++------------
.../CreateModal/functionTemplates.ts | 99 --------
.../mods/FunctionPanel/CreateModal/index.tsx | 106 +++-----
.../FunctionPanel/FunctionTemplate/index.tsx | 52 ----
.../functions/mods/FunctionPanel/index.tsx | 6 -
web/src/pages/app/mods/SideBar/index.tsx | 4 +-
.../app/setting/BillingDetails/index.tsx | 194 ++++++++-------
.../app/setting/CardRedemption/index.tsx | 4 +-
.../app/setting/RechargeHistory/index.tsx | 116 ++++-----
web/src/pages/app/setting/Usage/index.tsx | 10 +-
web/src/pages/app/setting/UserInfo/index.tsx | 16 +-
.../Mods/AddFunctionModal.tsx | 12 +-
.../CreateFuncTemplate/index.tsx | 2 -
.../FunctionPopover.tsx} | 0
.../Mods/MonacoEditor/index.tsx | 3 +-
.../Mods/TemplateCard/TemplateCard.tsx | 38 +--
.../UseTemplate/UseTemplateModal.tsx} | 2 +-
.../index.tsx} | 5 +-
.../{Mods/SideBar => }/index.module.scss | 0
web/src/pages/functionTemplate/index.tsx | 12 +-
web/src/pages/globalStore.ts | 4 +
web/src/pages/home/index.tsx | 11 +-
web/src/pages/home/mods/List/index.tsx | 6 +-
web/src/utils/getAvatarUrl.ts | 4 +-
26 files changed, 340 insertions(+), 616 deletions(-)
delete mode 100644 web/src/pages/app/functions/mods/FunctionPanel/CreateModal/functionTemplates.ts
delete mode 100644 web/src/pages/app/functions/mods/FunctionPanel/FunctionTemplate/index.tsx
rename web/src/pages/functionTemplate/Mods/{FunctionPopover/index.tsx => MonacoEditor/FunctionPopover.tsx} (100%)
rename web/src/pages/functionTemplate/Mods/{UseTemplateModal/index.tsx => TemplateInfo/UseTemplate/UseTemplateModal.tsx} (98%)
rename web/src/pages/functionTemplate/Mods/TemplateInfo/{UseTemplate.tsx => UseTemplate/index.tsx} (95%)
rename web/src/pages/functionTemplate/{Mods/SideBar => }/index.module.scss (100%)
diff --git a/web/src/components/CommonIcon/index.tsx b/web/src/components/CommonIcon/index.tsx
index ea3b2b0953..f82688971b 100644
--- a/web/src/components/CommonIcon/index.tsx
+++ b/web/src/components/CommonIcon/index.tsx
@@ -287,10 +287,16 @@ export const DomainIcon = createIcon({
export const FilterIcon = createIcon({
displayName: "FilterIcon",
- viewBox: "0 0 10 9",
+ viewBox: "0 0 10 8",
d: "M9.5 0V1H9L6.5 4.75V9H3.5V4.75L1 1H0.5V0H9.5ZM2.202 1L4.5 4.447V8H5.5V4.447L7.798 1H2.202Z",
});
+export const CalendarIcon = createIcon({
+ displayName: "CalendarIcon",
+ viewBox: "0 0 12 12",
+ d: "M2.5 11C2.225 11 1.9895 10.9022 1.7935 10.7065C1.59783 10.5105 1.5 10.275 1.5 10V3C1.5 2.725 1.59783 2.48967 1.7935 2.294C1.9895 2.098 2.225 2 2.5 2H3V1.4875C3 1.34583 3.04783 1.22917 3.1435 1.1375C3.2395 1.04583 3.35833 1 3.5 1C3.64167 1 3.7605 1.04783 3.8565 1.1435C3.95217 1.2395 4 1.35833 4 1.5V2H8V1.4875C8 1.34583 8.048 1.22917 8.144 1.1375C8.23967 1.04583 8.35833 1 8.5 1C8.64167 1 8.76033 1.04783 8.856 1.1435C8.952 1.2395 9 1.35833 9 1.5V2H9.5C9.775 2 10.0105 2.098 10.2065 2.294C10.4022 2.48967 10.5 2.725 10.5 3V10C10.5 10.275 10.4022 10.5105 10.2065 10.7065C10.0105 10.9022 9.775 11 9.5 11H2.5ZM2.5 10H9.5V5H2.5V10ZM2.5 4H9.5V3H2.5V4ZM2.5 4V3V4Z",
+});
+
export const ExitIcon = createIcon({
displayName: "ExitIcon",
viewBox: "0 0 20 20",
diff --git a/web/src/constants/index.ts b/web/src/constants/index.ts
index a27cc584ee..78369dcfdb 100644
--- a/web/src/constants/index.ts
+++ b/web/src/constants/index.ts
@@ -75,3 +75,11 @@ export const COLOR_MODE = {
};
export const LAF_AI_URL = "https://htr4n1.laf.run/laf-gpt";
+
+export const DEFAULT_CODE = `import cloud from '@lafjs/cloud'
+
+export default async function (ctx: FunctionContext) {
+ console.log('Hello World')
+ return { data: 'hi, laf' }
+}
+`;
diff --git a/web/src/layouts/Header/index.tsx b/web/src/layouts/Header/index.tsx
index 87372764cf..3e774c402b 100644
--- a/web/src/layouts/Header/index.tsx
+++ b/web/src/layouts/Header/index.tsx
@@ -1,7 +1,7 @@
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
-import { HamburgerIcon, MoonIcon, SunIcon } from "@chakra-ui/icons";
-import { Menu, MenuButton, MenuItem, MenuList, useColorMode } from "@chakra-ui/react";
+import { MoonIcon, SunIcon } from "@chakra-ui/icons";
+import { useColorMode } from "@chakra-ui/react";
import clsx from "clsx";
import { ChatIcon, TextIcon } from "@/components/CommonIcon";
@@ -16,7 +16,7 @@ import Language from "@/pages/homepage/language";
const Header = (props: { width: string }) => {
const { width } = props;
const { t } = useTranslation();
- const { userInfo } = useGlobalStore((state) => state);
+ const { userInfo, avatarUpdatedAt } = useGlobalStore((state) => state);
const { colorMode } = useColorMode();
const darkMode = colorMode === COLOR_MODE.dark;
@@ -39,11 +39,6 @@ const Header = (props: { width: string }) => {
ref: "https://forum.laf.run/",
icon: