From c63fe0d3a7d53df3a3a10c99f3ce1969b08c3cea Mon Sep 17 00:00:00 2001 From: NiklasBuchfink Date: Fri, 15 Mar 2024 11:27:40 +0100 Subject: [PATCH] debounce ForkModal after login --- .../src/interface/editor/EditorHeader.tsx | 2 +- .../pages/@host/@owner/@repository/+Page.tsx | 20 ++++++++++++++----- .../pages/@host/@owner/@repository/Layout.tsx | 9 ++++++++- .../@repository/components/Gitfloat.tsx | 12 +++++++++-- .../@repository/components/Listheader.tsx | 7 ++++++- .../@repository/components/PatternEditor.tsx | 3 ++- 6 files changed, 42 insertions(+), 11 deletions(-) diff --git a/inlang/source-code/editor/src/interface/editor/EditorHeader.tsx b/inlang/source-code/editor/src/interface/editor/EditorHeader.tsx index a1d2311805..9278b2d7a8 100644 --- a/inlang/source-code/editor/src/interface/editor/EditorHeader.tsx +++ b/inlang/source-code/editor/src/interface/editor/EditorHeader.tsx @@ -87,7 +87,7 @@ function EditorHeader() { )} -
+
diff --git a/inlang/source-code/editor/src/pages/@host/@owner/@repository/+Page.tsx b/inlang/source-code/editor/src/pages/@host/@owner/@repository/+Page.tsx index 90479912ce..13b3368380 100644 --- a/inlang/source-code/editor/src/pages/@host/@owner/@repository/+Page.tsx +++ b/inlang/source-code/editor/src/pages/@host/@owner/@repository/+Page.tsx @@ -38,8 +38,16 @@ export default function Page() { * is required to use the useEditorState hook. */ function TheActualPage() { - const { repo, currentBranch, project, projectList, routeParams, doesInlangConfigExist, tourStep, lixErrors } = - useEditorState() + const { + repo, + currentBranch, + project, + projectList, + routeParams, + doesInlangConfigExist, + tourStep, + lixErrors, + } = useEditorState() const [localStorage, setLocalStorage] = useLocalStorage() onMount(() => { @@ -65,9 +73,11 @@ function TheActualPage() { }) }) - createEffect(on([project, currentBranch], () => { - setMessageCount(0) - })) + createEffect( + on([project, currentBranch], () => { + setMessageCount(0) + }) + ) return ( <> diff --git a/inlang/source-code/editor/src/pages/@host/@owner/@repository/Layout.tsx b/inlang/source-code/editor/src/pages/@host/@owner/@repository/Layout.tsx index ccea52d054..2dbc33fa18 100644 --- a/inlang/source-code/editor/src/pages/@host/@owner/@repository/Layout.tsx +++ b/inlang/source-code/editor/src/pages/@host/@owner/@repository/Layout.tsx @@ -551,7 +551,14 @@ function ProjectMenu() { const shortenProjectName = (projectPath: string) => { const projectPathArray = projectPath.split("/") if (projectPathArray.length > 3) { - return "/" + projectPathArray.at(-3) + "/" + projectPathArray.at(-2) + "/" + projectPathArray.at(-1) + return ( + "/" + + projectPathArray.at(-3) + + "/" + + projectPathArray.at(-2) + + "/" + + projectPathArray.at(-1) + ) } return projectPath } diff --git a/inlang/source-code/editor/src/pages/@host/@owner/@repository/components/Gitfloat.tsx b/inlang/source-code/editor/src/pages/@host/@owner/@repository/components/Gitfloat.tsx index 4787b8b9ad..01ff21f5dc 100644 --- a/inlang/source-code/editor/src/pages/@host/@owner/@repository/components/Gitfloat.tsx +++ b/inlang/source-code/editor/src/pages/@host/@owner/@repository/components/Gitfloat.tsx @@ -21,6 +21,7 @@ import { } from "#src/services/auth/src/components/SignInDialog.jsx" import { WarningIcon } from "./Notification/NotificationHint.jsx" import IconArrowDownward from "~icons/material-symbols/arrow-downward-alt" +import { debounce } from "throttle-debounce" export const Gitfloat = () => { const { @@ -93,6 +94,8 @@ export const Gitfloat = () => { createEffect(() => { if (forkModalOpen()) { forkDialog?.show() + } else { + forkDialog?.hide() } }) @@ -278,9 +281,14 @@ export const Gitfloat = () => { if (gitState() === "login" && localChanges() > 2) setSignInModalOpen(true) }) - createEffect(() => { - if (gitState() === "fork" && localChanges() > 2) setForkModalOpen(true) + const debouncedForkModalState = debounce(2000, () => { + if (gitState() === "hasChanges") { + setForkModalOpen(false) + } else if (gitState() === "fork" && localChanges() > 2) { + setForkModalOpen(true) + } }) + createEffect(on([gitState, localChanges], debouncedForkModalState)) // prevent user from leaving the page when changes are not pushed const beforeUnloadHandler = (event: BeforeUnloadEvent) => { diff --git a/inlang/source-code/editor/src/pages/@host/@owner/@repository/components/Listheader.tsx b/inlang/source-code/editor/src/pages/@host/@owner/@repository/components/Listheader.tsx index f5950a48a1..84a618e022 100644 --- a/inlang/source-code/editor/src/pages/@host/@owner/@repository/components/Listheader.tsx +++ b/inlang/source-code/editor/src/pages/@host/@owner/@repository/components/Listheader.tsx @@ -154,7 +154,12 @@ export const ListHeader = () => { } prop:target="_blank" > - + Install lint rules diff --git a/inlang/source-code/editor/src/pages/@host/@owner/@repository/components/PatternEditor.tsx b/inlang/source-code/editor/src/pages/@host/@owner/@repository/components/PatternEditor.tsx index 1bd142ed0a..a5d95f73d9 100644 --- a/inlang/source-code/editor/src/pages/@host/@owner/@repository/components/PatternEditor.tsx +++ b/inlang/source-code/editor/src/pages/@host/@owner/@repository/components/PatternEditor.tsx @@ -165,7 +165,8 @@ export function PatternEditor(props: { }) } }) - )) + ) + ) const autoSave = () => { let newMessage