-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: skeleton animation when fetching files (closes #63)
- Loading branch information
Showing
9 changed files
with
119 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
import styled from 'styled-components'; | ||
import styled, { css, keyframes } from 'styled-components'; | ||
import { SelectionArea } from 'rectangle-selection'; | ||
|
||
import { APPBAR_HEIGHT, FILE_HEIGHT } from '../../constants'; | ||
|
||
export const StyledPage = styled(SelectionArea)` | ||
export const StyledPage = styled.div` | ||
width: 100%; | ||
height: calc(100% - ${APPBAR_HEIGHT}px); | ||
overflow-y: auto; | ||
`; | ||
|
||
export const StyledPageGridBase = css` | ||
width: 100%; | ||
height: 100%; | ||
display: grid; | ||
grid-gap: 16px; | ||
grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); | ||
grid-template-rows: 1fr; | ||
grid-template-rows: repeat(auto-fill, ${FILE_HEIGHT}px); | ||
background-color: rgba(0, 0, 0, 0.12); | ||
`; | ||
|
||
export const Grid = styled(SelectionArea)` | ||
overflow-y: auto; | ||
${StyledPageGridBase}; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react'; | ||
|
||
import { StyledFile } from '~/renderer/app/components/File/style'; | ||
import { SkeletonCircle, SkeletonText } from '../Skeleton'; | ||
import { getRandomNumber } from '~/renderer/utils'; | ||
import { StyledFilesSkeleton, ANIMATION_TIME } from './style'; | ||
|
||
const Item = () => { | ||
return ( | ||
<StyledFile> | ||
<SkeletonCircle style={{ width: 48, height: 48, margin: '8px 0px' }} /> | ||
<SkeletonText style={{ height: 16, borderRadius: 4 }} /> | ||
</StyledFile> | ||
); | ||
}; | ||
|
||
export const FilesSkeleton = () => { | ||
const [count, setCount] = React.useState(0); | ||
const ref = React.useRef<HTMLDivElement>(); | ||
|
||
const timeout = React.useRef<NodeJS.Timeout>(); | ||
|
||
const onTimeout = React.useCallback(() => { | ||
if (!ref.current) return; | ||
|
||
ref.current.style.display = 'none'; | ||
|
||
setCount(getRandomNumber(10, 30)); | ||
|
||
requestAnimationFrame(() => { | ||
ref.current.style.display = 'grid'; | ||
setTimeout(onTimeout, ANIMATION_TIME); | ||
}); | ||
}, []); | ||
|
||
React.useEffect(() => { | ||
setTimeout(onTimeout); | ||
|
||
return () => { | ||
clearTimeout(timeout.current); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<StyledFilesSkeleton ref={ref}> | ||
{[...Array(count).keys()].map((_, index) => ( | ||
<Item key={index} /> | ||
))} | ||
</StyledFilesSkeleton> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import styled, { keyframes } from 'styled-components'; | ||
|
||
import { EASING_FUNCTION } from '~/renderer/app/constants'; | ||
import { StyledPageGridBase } from '~/renderer/app/components/Page/style'; | ||
|
||
export const ANIMATION_TIME = 1600; | ||
|
||
const animation = keyframes` | ||
0% { | ||
opacity: 0; | ||
transform: translateY(64px); | ||
} | ||
25%, 80% { | ||
opacity: 1; | ||
transform: translateY(0px); | ||
} | ||
100% { | ||
opacity: 0; | ||
} | ||
`; | ||
|
||
export const StyledFilesSkeleton = styled.div` | ||
overflow: hidden; | ||
animation: ${animation} ${ANIMATION_TIME}ms ${EASING_FUNCTION} infinite; | ||
${StyledPageGridBase}; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters