Skip to content

Commit

Permalink
add: loading
Browse files Browse the repository at this point in the history
  • Loading branch information
hengstchon committed Mar 16, 2021
1 parent 259ccc9 commit 0df6a8f
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 12 deletions.
1 change: 0 additions & 1 deletion components/Item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const Item = ({ item }) => {
<div className="text-sm pt-2 text-gray-400">
{dayjs(isoDate).fromNow()}
</div>
<div className="text-sm pt-2">{isoDate}</div>
<div className="pt-2 text-text">{content}</div>
</div>
)
Expand Down
10 changes: 10 additions & 0 deletions components/Loading.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const Loading = () => {
return (
<div className="bg-bg flex flex-col mt-20 items-center">
<img src="/images/loading.svg" width="100" height="100" alt="loading" />
<span className="text-center text-lg text-white">Loading...</span>
</div>
)
}

export default Loading
2 changes: 1 addition & 1 deletion components/Nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Nav = ({ navName }) => {
></div>

<aside
className={`fixed top-0 left-0 w-64 h-full overflow-auto transition-all ease-in-out duration-300 transform z-50 ${
className={`fixed top-0 left-0 w-64 h-full overflow-auto overscroll-contain transition-all ease-in-out duration-300 transform z-50 ${
isOpen ? 'translate-x-0' : '-translate-x-full'
} lg:transform-none lg:border-r lg:border-gray-600 bg-gray-700 lg:bg-bg`}
>
Expand Down
19 changes: 13 additions & 6 deletions components/Page.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import Item from './Item'
import Pagination from './Pagination'
import Loading from './Loading'

const Page = ({ pageItems, totalPage, page }) => {
return (
<div className="flex">
<div className="lg:w-64 invisible"></div>
<div className="container lg:max-w-screen-md mx-auto px-2 mt-5 divide-y divide-gray-600">
{pageItems.map((item, index) => (
<Item key={index} item={item}></Item>
))}
<div className="pt-6 pb-10">
<Pagination totalPage={totalPage} page={parseInt(page)} />
</div>
{pageItems ? (
<div>
{pageItems.map((item, index) => (
<Item key={index} item={item}></Item>
))}
<div className="pt-6 pb-10">
<Pagination totalPage={totalPage} page={parseInt(page)} />
</div>
</div>
) : (
<Loading />
)}
</div>
</div>
)
Expand Down
5 changes: 1 addition & 4 deletions pages/[cat].jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default function Content() {
const page = router.query.page || '1'
const { data } = useSWR(`/api/${cat}?page=${page}`, fetcher)
const { navName, totalPage, pageItems } = data || {}

return (
<div className="bg-bg text-white">
<Head>
Expand All @@ -21,9 +20,7 @@ export default function Content() {

<Nav navName={navName} />

{pageItems && (
<Page pageItems={pageItems} totalPage={totalPage} page={page} />
)}
<Page pageItems={pageItems} totalPage={totalPage} page={page} />
</div>
)
}
51 changes: 51 additions & 0 deletions public/images/loading.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit 0df6a8f

@vercel
Copy link

@vercel vercel bot commented on 0df6a8f Mar 16, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.