Browse Source

feat: auto update

Ahmad Kholid 2 years ago
parent
commit
16bfe9ee80
2 changed files with 22 additions and 0 deletions
  1. 21 0
      src/newtab/pages/workflows/[id].vue
  2. 1 0
      src/utils/handleFormElement.js

+ 21 - 0
src/newtab/pages/workflows/[id].vue

@@ -1052,6 +1052,23 @@ function checkWorkflowPermission() {
     permissionState.showModal = true;
   });
 }
+function checkWorkflowUpdate() {
+  const updatedAt = encodeURIComponent(workflow.value.updatedAt);
+  fetchApi(
+    `/teams/${teamId}/workflows/${workflowId}/check-update?updatedAt=${updatedAt}`
+  )
+    .then((response) => response.json())
+    .then((result) => {
+      if (!result) return;
+
+      updateWorkflow(result).then(() => {
+        window.location.reload();
+      });
+    })
+    .catch((error) => {
+      console.error(error);
+    });
+}
 
 const shortcut = useShortcut([
   getShortcut('editor:toggle-sidebar', toggleSidebar),
@@ -1101,6 +1118,10 @@ onMounted(() => {
   if (route.query.permission || (isTeamWorkflow && !haveEditAccess.value))
     checkWorkflowPermission();
 
+  if (isTeamWorkflow && !haveEditAccess.value && workflow.value.updatedAt) {
+    checkWorkflowUpdate();
+  }
+
   if (workflow.value.connectedTable) {
     fetchConnectedTable();
   }

+ 1 - 0
src/utils/handleFormElement.js

@@ -52,6 +52,7 @@ function formEvent(element, data) {
 }
 async function inputText({ data, element, isEditable }) {
   element?.focus();
+  element?.click();
   const elementKey = isEditable ? 'textContent' : 'value';
 
   if (data.delay > 0 && !document.hidden) {