2
0

refactor: ♻️ Migrate from short-uuid to cuid lib

This commit is contained in:
Baptiste Arnaud
2022-03-18 12:30:42 +01:00
parent 64bafd15a1
commit 1423c14547
47 changed files with 120 additions and 132 deletions

View File

@ -39,11 +39,11 @@ import { useRegisterActions } from 'kbar'
import useUndo from 'services/utils/useUndo'
import { useDebounce } from 'use-debounce'
import { itemsAction, ItemsActions } from './actions/items'
import { generate } from 'short-uuid'
import { dequal } from 'dequal'
import { User } from 'db'
import { saveWebhook } from 'services/webhook'
import { stringify } from 'qs'
import cuid from 'cuid'
const autoSaveTimeout = 10000
type UpdateTypebotPayload = Partial<{
@ -291,7 +291,7 @@ export const TypebotContext = ({
const publishTypebot = async () => {
if (!localTypebot) return
const publishedTypebotId = generate()
const publishedTypebotId = cuid()
const newLocalTypebot = { ...localTypebot }
if (publishedTypebot && isNotDefined(localTypebot.publishedTypebotId)) {
updateLocalTypebot({ publishedTypebotId: publishedTypebot.id })

View File

@ -1,9 +1,9 @@
import { Typebot, Edge, StepWithItems, StepIndices, ItemIndices } from 'models'
import { WritableDraft } from 'immer/dist/types/types-external'
import { generate } from 'short-uuid'
import { SetTypebot } from '../TypebotContext'
import { produce } from 'immer'
import { byId, isDefined, stepHasItems } from 'utils'
import cuid from 'cuid'
export type EdgesActions = {
createEdge: (edge: Omit<Edge, 'id'>) => void
@ -17,7 +17,7 @@ export const edgesAction = (setTypebot: SetTypebot): EdgesActions => ({
produce(typebot, (typebot) => {
const newEdge = {
...edge,
id: generate(),
id: cuid(),
}
removeExistingEdge(typebot, edge)
typebot.edges.push(newEdge)
@ -73,11 +73,10 @@ const addEdgeIdToItem = (
typebot: WritableDraft<Typebot>,
edgeId: string,
{ blockIndex, stepIndex, itemIndex }: ItemIndices
) => {
;(typebot.blocks[blockIndex].steps[stepIndex] as StepWithItems).items[
) =>
((typebot.blocks[blockIndex].steps[stepIndex] as StepWithItems).items[
itemIndex
].outgoingEdgeId = edgeId
}
].outgoingEdgeId = edgeId)
export const deleteEdgeDraft = (
typebot: WritableDraft<Typebot>,
@ -107,11 +106,10 @@ const deleteOutgoingEdgeIdProps = (
if (fromStepIndex !== -1)
typebot.blocks[fromBlockIndex].steps[fromStepIndex].outgoingEdgeId =
undefined
if (fromItemIndex !== -1) {
;(
if (fromItemIndex !== -1)
(
typebot.blocks[fromBlockIndex].steps[fromStepIndex] as StepWithItems
).items[fromItemIndex].outgoingEdgeId = undefined
}
}
export const cleanUpEdgeDraft = (

View File

@ -9,7 +9,7 @@ import { SetTypebot } from '../TypebotContext'
import produce from 'immer'
import { cleanUpEdgeDraft } from './edges'
import { stepHasItems } from 'utils'
import { generate } from 'short-uuid'
import cuid from 'cuid'
export type ItemsActions = {
createItem: (item: Omit<ButtonItem, 'id'>, indices: ItemIndices) => void
@ -29,7 +29,7 @@ const itemsAction = (setTypebot: SetTypebot): ItemsActions => ({
step.items.splice(itemIndex, 0, {
...item,
stepId: step.id,
id: generate(),
id: cuid(),
})
})
),