-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💄 Hide blob list by default and add image viewer (#252)
* ✨ Allow reverseTakedown from workspace * 💄 Adjust z-index in various places to fix content overlapping * 💄 Hide blob list by default and add image viewer * ♻️ Refactor per review feedback
- Loading branch information
Showing
8 changed files
with
193 additions
and
39 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { useServerConfig } from '@/shell/ConfigurationContext' | ||
import { ToolsOzoneModerationDefs } from '@atproto/api' | ||
import { useCallback } from 'react' | ||
import Lightbox from 'yet-another-react-lightbox' | ||
import Captions from 'yet-another-react-lightbox/plugins/captions' | ||
import Thumbnails from 'yet-another-react-lightbox/plugins/thumbnails' | ||
|
||
export const useBlobUrl = ({ authorDid }: { authorDid: string }) => { | ||
const { appview } = useServerConfig() | ||
const cdnUrl = appview?.endsWith('.bsky.app') | ||
? 'https://cdn.bsky.app' | ||
: appview | ||
|
||
return useCallback( | ||
({ | ||
cid, | ||
isAvatar, | ||
size = 'fullsize', | ||
}: { | ||
cid: string | ||
isAvatar?: boolean | ||
size?: 'thumbnail' | 'fullsize' | ||
}) => { | ||
let sourcePath = isAvatar ? 'avatar' : 'feed' | ||
|
||
// avatar_fullsize doesn't exist, instead the default avatar/ serves the full size image | ||
if (!isAvatar && size !== 'fullsize') { | ||
sourcePath += `_${size}` | ||
} | ||
|
||
return `${cdnUrl}/img/feed_${size}/plain/${authorDid}/${cid}@jpeg` | ||
}, | ||
[authorDid, cdnUrl], | ||
) | ||
} | ||
|
||
export const BlobListLightbox = ({ | ||
authorDid, | ||
blobs, | ||
onClose, | ||
slideIndex, | ||
}: { | ||
authorDid: string | ||
blobs: ToolsOzoneModerationDefs.BlobView[] | ||
onClose: () => void | ||
slideIndex: number | ||
}) => { | ||
const getBlobUrl = useBlobUrl({ authorDid }) | ||
const handleKeyDown = (event) => { | ||
if (event.key === 'Escape') { | ||
event.stopPropagation() | ||
} | ||
} | ||
|
||
return ( | ||
<Lightbox | ||
open={slideIndex >= 0} | ||
plugins={[Thumbnails, Captions]} | ||
carousel={{ finite: true }} | ||
controller={{ closeOnBackdropClick: true }} | ||
close={onClose} | ||
slides={blobs.map((blob) => ({ | ||
src: getBlobUrl({ | ||
cid: blob.cid, | ||
}), | ||
}))} | ||
index={slideIndex} | ||
on={{ | ||
// The lightbox may open from other Dialog/modal components | ||
// in that case, we want to make sure that esc button presses | ||
// only close the lightbox and not the parent Dialog/modal underneath | ||
entered: () => { | ||
document.addEventListener('keydown', handleKeyDown) | ||
}, | ||
exited: () => { | ||
document.removeEventListener('keydown', handleKeyDown) | ||
}, | ||
}} | ||
/> | ||
) | ||
} |
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
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 |
---|---|---|
|
@@ -180,4 +180,4 @@ export function simpleHash(str: string) { | |
hash = ((hash << 5) - hash + chr) | 0 | ||
} | ||
return hash | ||
} | ||
} |