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 warnings #25

Merged
merged 3 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Improve stability
  • Loading branch information
tlenclos committed Feb 9, 2020
commit dddb30f50fe58ddcaad935217152ac969563013a
2 changes: 1 addition & 1 deletion src/components/editor/previews/AccordionPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { useInteractive } from '../../../hooks/useInteractive'
import { useDropComponent } from '../../../hooks/useDropComponent'
import { Box, Accordion, AccordionHeader, AccordionIcon } from '@chakra-ui/core'
import { Box, Accordion, AccordionHeader } from '@chakra-ui/core'
import ComponentPreview from '../ComponentPreview'

const acceptedTypes = [
Expand Down
23 changes: 13 additions & 10 deletions src/components/inspector/children/ChildrenList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ const ChildrenList: React.FC<Props> = ({
}) => {
return (
<Box mx={2} h="100%">
{childrenList.map((child, index) => (
<ChildElement
key={child.id}
type={child.type}
index={index}
moveItem={moveItem}
id={child.id}
onSelect={onSelect}
/>
))}
{childrenList.map(
(child, index) =>
child && (
<ChildElement
key={child.id}
type={child.type}
index={index}
moveItem={moveItem}
id={child.id}
onSelect={onSelect}
/>
),
)}
</Box>
)
}
Expand Down
9 changes: 6 additions & 3 deletions src/core/models/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ export type AppState = {
}

export const generateId = () => {
return `comp-${Math.random()
.toString(36)
.substr(2, 9)}`
return `comp-${(
Date.now().toString(36) +
Math.random()
.toString(36)
.substr(2, 5)
).toUpperCase()}`
}

const app = createModel({
Expand Down
12 changes: 7 additions & 5 deletions src/core/models/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createModel } from '@rematch/core'
import { DEFAULT_PROPS } from '../../utils/defaultProps'
import omit from 'lodash/omit'
import { airbnbCard } from '../../theme/demo'
import { generateId } from './app'

type ComponentsState = {
components: IComponents
Expand Down Expand Up @@ -97,10 +98,11 @@ const components = createModel({
id: IComponent['id'],
) => {
children.forEach(child => {
deleteRecursive(
updatedComponents[child].children,
updatedComponents[child].id,
)
updatedComponents[child] &&
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@foyarash j'ai pas cherché en détail mais ce cas là arrivait parfois et ca faisait crasher l'appli. Il faudrai rajouter des tests sur la fonction 👀 .

deleteRecursive(
updatedComponents[child].children,
updatedComponents[child].id,
)
})

updatedComponents = omit(updatedComponents, id)
Expand Down Expand Up @@ -186,7 +188,7 @@ const components = createModel({
rootParentType?: ComponentType
},
): ComponentsState {
const id = `comp-${Math.round(new Date().getTime() / 1000)}`
const id = generateId()

return {
...state,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/defaultProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export const DEFAULT_PROPS: PreviewDefaultProps = {
Checkbox: {
...Checkbox.defaultProps,
children: 'Lorem Ipsum',
isChecked: true,
isReadOnly: true,
},
AvatarBadge: {
...AvatarBadge.defaultProps,
Expand Down