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

fix: compile res data #549

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion web/public/locales/zh-CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"DeleteConfirm": "确认要删除函数吗?",
"SearchPlacehoder": "输入函数名搜索",
"CreateTime": "创建时间",
"Editting...": "编辑中...",
"Editting...": "编辑中 (Ctrl/⌘ + S 保存)",
"LocalSaved...": "已保存本地",
"LocalSavedTip": "(代码已保存到本地,可直接发起调试)",
"FunctionPanel": {
"Debug": "调试",
"Deploy": "发布",
Expand Down
29 changes: 23 additions & 6 deletions web/src/pages/app/functions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* cloud functions index page
***************************/

import { useState } from "react";
import { Badge, Button, Center, HStack } from "@chakra-ui/react";
import { t } from "i18next";

Expand All @@ -26,14 +27,16 @@ import useGlobalStore from "@/pages/globalStore";

function FunctionPage() {
const store = useFunctionStore((store) => store);
const { currentFunction, updateFunctionCode } = store;
const { currentFunction, updateFunctionCode, functionCodes } = store;

const functionCache = useFunctionCache();

const { showSuccess } = useGlobalStore((state) => state);

const updateFunctionMutation = useUpdateFunctionMutation();

const [localSaved, setLocalSaved] = useState(false);

const deploy = async () => {
const res = await updateFunctionMutation.mutateAsync({
description: currentFunction?.desc,
Expand All @@ -55,7 +58,8 @@ function FunctionPage() {
});

useHotKey("s", async () => {
// functionCache.setCache(currentFunction!.id, functionCodes[currentFunction!.id]);
setLocalSaved(true);
functionCache.setCache(currentFunction!.id, functionCodes[currentFunction!.id]);
});

return (
Expand All @@ -78,11 +82,23 @@ function FunctionPage() {
</span>
</span>
<span className="ml-4 ">
{currentFunction?.id &&
{localSaved ? (
<div>
<Badge colorScheme="gray" className="mr-2">
{t("LocalSaved...")}
</Badge>
<span className="ml-2 text-slate-500 text-sm">{t("LocalSavedTip")}</span>
</div>
) : (
currentFunction?.id &&
functionCache.getCache(currentFunction?.id) !==
currentFunction?.source?.code && (
<Badge colorScheme="purple">{t("Editting...")}</Badge>
)}
<div>
<Badge colorScheme="purple">{t("Editting...")}</Badge>{" "}
</div>
)
)}

{/* <FileStatusIcon status={FileStatus.deleted} /> */}
</span>
</div>
Expand Down Expand Up @@ -115,8 +131,9 @@ function FunctionPage() {
path={currentFunction?.name || ""}
value={functionCache.getCache(currentFunction!.id)}
onChange={(value) => {
setLocalSaved(false);
updateFunctionCode(currentFunction, value || "");
functionCache.setCache(currentFunction!.id, value || "");
// functionCache.setCache(currentFunction!.id, value || "");
}}
/>
) : (
Expand Down
4 changes: 2 additions & 2 deletions web/src/pages/app/functions/mods/DebugPannel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ export default function DebugPanel() {
code: functionCache.getCache(currentFunction!.id),
name: currentFunction!.name,
});
if (compileRes.id) {
if (!compileRes.error) {
maslow marked this conversation as resolved.
Show resolved Hide resolved
const res = await axios({
url: getFunctionDebugUrl(),
method: "post",
data: {
func: compileRes || "",
func: compileRes.data || "",
param: JSON.parse(params),
},
headers: {
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/app/functions/mods/FunctionPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* cloud functions list sidebar
***************************/

import React, { useEffect, useState } from "react";
import { useEffect, useState } from "react";
import { DeleteIcon, Search2Icon } from "@chakra-ui/icons";
import { Input, InputGroup, InputLeftElement } from "@chakra-ui/react";
import { t } from "i18next";
Expand Down