Fix state change after unmount (#2653)

This commit is contained in:
Jesús Espino 2022-03-29 10:02:24 +02:00 committed by GitHub
parent fca768ca46
commit 833e759b49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,21 +27,27 @@ const BoardTemplateSelectorPreview = (props: Props) => {
const [activeTemplateCards, setActiveTemplateCards] = useState<Card[]>([])
useEffect(() => {
let isSubscribed = true
if (activeTemplate) {
setActiveTemplateCards([])
setActiveView(null)
setActiveTemplateCards([])
octoClient.getAllBlocks(activeTemplate.id).then((blocks) => {
const cards = blocks.filter((b) => b.type === 'card')
const views = blocks.filter((b) => b.type === 'view').sort((a, b) => a.title.localeCompare(b.title))
if (views.length > 0) {
setActiveView(views[0] as BoardView)
}
if (cards.length > 0) {
setActiveTemplateCards(cards as Card[])
if (isSubscribed) {
const cards = blocks.filter((b) => b.type === 'card')
const views = blocks.filter((b) => b.type === 'view').sort((a, b) => a.title.localeCompare(b.title))
if (views.length > 0) {
setActiveView(views[0] as BoardView)
}
if (cards.length > 0) {
setActiveTemplateCards(cards as Card[])
}
}
})
}
return () => {
isSubscribed = false
}
}, [activeTemplate])
const dateDisplayProperty = useMemo(() => {