parent
3825968106
commit
ae72680a5b
11 changed files with 144 additions and 4 deletions
@ -0,0 +1,29 @@ |
||||
import { useStore } from '@nanostores/preact'; |
||||
import { pageLoadingMessage } from '../stores/page'; |
||||
import SpinnerIcon from '../icons/spinner.svg'; |
||||
|
||||
export function PageProgress() { |
||||
const $pageLoadingMessage = useStore(pageLoadingMessage); |
||||
if (!$pageLoadingMessage) { |
||||
return null; |
||||
} |
||||
|
||||
return ( |
||||
<div> |
||||
{/* Tailwind based spinner for full page */} |
||||
<div className="fixed left-0 top-0 z-50 flex h-full w-full items-center justify-center bg-white bg-opacity-75"> |
||||
<div class="flex items-center justify-center rounded-md border bg-white px-4 py-2 "> |
||||
<img |
||||
src={SpinnerIcon} |
||||
alt="Loading" |
||||
className="h-4 w-4 animate-spin fill-blue-600 text-gray-200 sm:h-4 sm:w-4" |
||||
/> |
||||
<h1 className="ml-2"> |
||||
{$pageLoadingMessage} |
||||
<span className="animate-pulse">...</span> |
||||
</h1> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
); |
||||
} |
@ -0,0 +1,30 @@ |
||||
import { useEffect } from 'preact/hooks'; |
||||
import type { ResourceType } from '../lib/resource-progress'; |
||||
|
||||
type CallbackType = (data: { |
||||
resourceType: ResourceType; |
||||
resourceId: string; |
||||
topicId: string; |
||||
}) => void; |
||||
|
||||
export function useToggleTopic(callback: CallbackType) { |
||||
useEffect(() => { |
||||
function handleToggleTopic(e: any) { |
||||
const { resourceType, resourceId, topicId } = e.detail; |
||||
|
||||
callback({ |
||||
resourceType, |
||||
resourceId, |
||||
topicId, |
||||
}); |
||||
} |
||||
|
||||
window.addEventListener(`best-practice.topic.toggle`, handleToggleTopic); |
||||
return () => { |
||||
window.removeEventListener( |
||||
`best-practice.topic.toggle`, |
||||
handleToggleTopic |
||||
); |
||||
}; |
||||
}, []); |
||||
} |
@ -0,0 +1,3 @@ |
||||
import { atom } from 'nanostores'; |
||||
|
||||
export const pageLoadingMessage = atom(''); |
Loading…
Reference in new issue