Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
improvement(files): show loading spinner in file preview content area#5610
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,34 @@ | ||
| 'use client' | ||
| import { memo } from 'react' | ||
| import { memo, useState } from 'react' | ||
| import type { WorkspaceFileRecord } from '@/lib/uploads/contexts/workspace' | ||
| import { useFileContentSource } from '@/hooks/use-file-content-source' | ||
| import { PREVIEW_LOADING_OVERLAY } from './preview-shared' | ||
| import { ZoomablePreview } from './zoomable-preview' | ||
| export const ImagePreview = memo(function ImagePreview({ file }: { file: WorkspaceFileRecord }) { | ||
| const source = useFileContentSource() | ||
| const [hasSettled, setHasSettled] = useState(false) | ||
| // Version the URL on updatedAt: overwrites keep the same storage key, so an unversioned | ||
| // URL would resolve to a previously cached copy instead of the rewritten bytes. | ||
| const serveUrl = source.buildUrl(file.key, { | ||
| version: Number(new Date(file.updatedAt)) || file.size, | ||
| }) | ||
waleedlatif1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| return ( | ||
waleedlatif1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| <ZoomablePreview className='flex flex-1' contentClassName='h-full w-full'> | ||
| <img | ||
| src={serveUrl} | ||
| alt={file.name} | ||
| className='max-h-full max-w-full select-none rounded-md object-contain' | ||
| draggable={false} | ||
| loading='eager' | ||
| /> | ||
| </ZoomablePreview> | ||
| <div className='relative flex min-h-0 flex-1 flex-col'> | ||
| <ZoomablePreview className='flex flex-1' contentClassName='h-full w-full'> | ||
| <img | ||
| src={serveUrl} | ||
| alt={file.name} | ||
| className='max-h-full max-w-full select-none rounded-md object-contain' | ||
| draggable={false} | ||
| loading='eager' | ||
| onLoad={() => setHasSettled(true)} | ||
| onError={() => setHasSettled(true)} | ||
| /> | ||
| </ZoomablePreview> | ||
| {!hasSettled && PREVIEW_LOADING_OVERLAY} | ||
waleedlatif1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| </div> | ||
| ) | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.