Skip to content

Commit

Permalink
fix(editor): ♿️ Better autoSave handler
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Feb 25, 2022
1 parent 2a6a474 commit 8171edb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 2 additions & 9 deletions apps/builder/components/shared/TypebotHeader/TypebotHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ export const TypebotHeader = () => {
} = useTypebot()
const { setRightPanel } = useEditor()

const handleBackClick = async () => {
await save()
router.push({
pathname: `/typebots`,
query: { ...router.query, typebotId: [] },
})
}

const handleNameSubmit = (name: string) => updateOnBothTypebots({ name })

const handlePreviewClick = async () => {
Expand Down Expand Up @@ -113,9 +105,10 @@ export const TypebotHeader = () => {
>
<HStack alignItems="center">
<IconButton
as={NextChakraLink}
aria-label="Back"
icon={<ChevronLeftIcon fontSize={30} />}
onClick={handleBackClick}
href="/typebots"
/>
{typebot?.name && (
<EditableTypebotName
Expand Down
10 changes: 9 additions & 1 deletion apps/builder/contexts/TypebotContext/TypebotContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useToast } from '@chakra-ui/react'
import { PublicTypebot, Settings, Theme, Typebot } from 'models'
import { useRouter } from 'next/router'
import { Router, useRouter } from 'next/router'
import {
createContext,
ReactNode,
Expand Down Expand Up @@ -157,6 +157,14 @@ export const TypebotContext = ({
debounceTimeout: autoSaveTimeout,
})

useEffect(() => {
Router.events.on('routeChangeStart', saveTypebot)
return () => {
Router.events.off('routeChangeStart', saveTypebot)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

const [isSavingLoading, setIsSavingLoading] = useState(false)
const [isPublishing, setIsPublishing] = useState(false)

Expand Down

2 comments on commit 8171edb

@vercel
Copy link

@vercel vercel bot commented on 8171edb Feb 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
app.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 8171edb Feb 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.