mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-10 01:03:36 -05:00
Add (basic implementation of) background for loading images
This commit is contained in:
parent
4abf98adcb
commit
1b4d1e73df
2 changed files with 10 additions and 0 deletions
|
@ -93,3 +93,7 @@
|
||||||
.image {
|
.image {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.loading {
|
||||||
|
background: var(--background);
|
||||||
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ export default function Attachment({ attachment, hasContent }: Props) {
|
||||||
const { openScreen } = useIntermediate();
|
const { openScreen } = useIntermediate();
|
||||||
const { filename, metadata } = attachment;
|
const { filename, metadata } = attachment;
|
||||||
const [spoiler, setSpoiler] = useState(filename.startsWith("SPOILER_"));
|
const [spoiler, setSpoiler] = useState(filename.startsWith("SPOILER_"));
|
||||||
|
// only used in image attachments
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
const url = client.generateFileURL(
|
const url = client.generateFileURL(
|
||||||
attachment,
|
attachment,
|
||||||
|
@ -39,6 +41,7 @@ export default function Attachment({ attachment, hasContent }: Props) {
|
||||||
height={metadata.height}
|
height={metadata.height}
|
||||||
className={classNames({
|
className={classNames({
|
||||||
[styles.margin]: hasContent,
|
[styles.margin]: hasContent,
|
||||||
|
[styles.loading]: loading,
|
||||||
spoiler,
|
spoiler,
|
||||||
})}>
|
})}>
|
||||||
<img
|
<img
|
||||||
|
@ -49,6 +52,9 @@ export default function Attachment({ attachment, hasContent }: Props) {
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
openScreen({ id: "image_viewer", attachment })
|
openScreen({ id: "image_viewer", attachment })
|
||||||
}
|
}
|
||||||
|
onLoad={() =>
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
onMouseDown={(ev) =>
|
onMouseDown={(ev) =>
|
||||||
ev.button === 1 && window.open(url, "_blank")
|
ev.button === 1 && window.open(url, "_blank")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue