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

feat: add loading spinner animation #291

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions frontend/.changeset/empty-numbers-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@liam-hq/erd-core": patch
"@liam-hq/cli": patch
---

💄 add loading spinner
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@
height: 100%;
background-color: var(--global-background);
}

.loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { type FC, useCallback, useState } from 'react'
import styles from './ERDContent.module.css'
import { ERDContentProvider, useERDContentContext } from './ERDContentContext'
import { RelationshipEdge } from './RelationshipEdge'
import { Spinner } from './Spinner'
import { TableNode } from './TableNode'
import { useFitViewWhenActiveTableChange } from './useFitViewWhenActiveTableChange'
import { useInitialAutoLayout } from './useInitialAutoLayout'
Expand Down Expand Up @@ -290,6 +291,7 @@ export const ERDContentInner: FC<Props> = ({

return (
<div className={styles.wrapper} data-loading={loading}>
{loading && <Spinner className={styles.loading} />}
<ReactFlow
nodes={nodes.map((node) => ({
...node,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@keyframes spin {
from {
transform: rotate(0);
}
to {
transform: rotate(359deg);
}
}

.spinnerBox {
width: 300px;
height: 300px;
display: flex;
justify-content: center;
align-items: center;
background-color: transparent;
pointer-events: none;
}

.circleBorder {
width: 100px;
height: 100px;
padding: 1px;
display: flex;
justify-content: center;
align-items: center;
border-radius: 50%;
background: #141616;
background: linear-gradient(
0deg,
rgba(29, 237, 131, 0.05) 33%,
rgba(29, 237, 131, 1) 100%
);
animation: spin 1.2s linear 0s infinite;
}

.circleCore {
width: 100%;
height: 100%;
background-color: #141616;
border-radius: 50%;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import clsx from 'clsx'
import type { FC } from 'react'
import styles from './Spinner.module.css'

type Props = {
className?: string
}

export const Spinner: FC<Props> = ({ className }) => {
return (
<span className={clsx(styles.spinnerBox, className)}>
<span className={styles.circleBorder}>
<span className={styles.circleCore} />
</span>
</span>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Spinner'
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ export const useAutoLayout = () => {
})

setNodes([...hiddenNodes, ...newNodes])
setLoading(false)
setInitializeComplete(true)
setTimeout(() => fitView(fitViewOptions), 0)
setTimeout(() => {
fitView(fitViewOptions)
setLoading(false)
setInitializeComplete(true)
}, 0)
Copy link
Member Author

Choose a reason for hiding this comment

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

📝 Delaying the end of loading reduces flickering.

},
[getNodes, setNodes, getEdges, fitView, setLoading, setInitializeComplete],
)
Expand Down
Loading