-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
79 additions
and
16 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
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 |
---|---|---|
@@ -1,20 +1,64 @@ | ||
import { Entity } from 'megalodon' | ||
import { useState } from 'react' | ||
import { Blurhash } from 'react-blurhash' | ||
import { FaEyeSlash } from 'react-icons/fa6' | ||
import { FormattedMessage } from 'react-intl' | ||
|
||
type Props = { | ||
media: Array<Entity.Attachment> | ||
sensitive: boolean | ||
} | ||
export default function Media(props: Props) { | ||
const [sensitive, setSensitive] = useState(props.sensitive) | ||
|
||
return ( | ||
<div className="mt-2 flex flex-wrap"> | ||
{props.media.map((media, key) => ( | ||
<img | ||
key={key} | ||
src={media.preview_url} | ||
className="h-36 mr-2 mb-2 rounded-md max-w-full cursor-pointer" | ||
alt={media.description} | ||
title={media.description} | ||
/> | ||
))} | ||
<div className="relative"> | ||
{sensitive ? ( | ||
<button className="absolute bg-gray-600 text-gray-200 top-1 left-1 p-1 rounded z-10" onClick={() => setSensitive(false)}> | ||
<FormattedMessage id="timeline.status.cw" /> | ||
</button> | ||
) : ( | ||
<button className="absolute bg-gray-600 text-gray-200 top-1 left-1 p-1 rounded z-10" onClick={() => setSensitive(true)}> | ||
<FaEyeSlash /> | ||
</button> | ||
)} | ||
|
||
<div className="mt-2 flex flex-wrap gap-2"> | ||
{props.media.map((media, key) => ( | ||
<div key={key}> | ||
<Attachment attachment={media} sensitive={sensitive} /> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
type AttachmentProps = { | ||
attachment: Entity.Attachment | ||
sensitive: boolean | ||
} | ||
|
||
function Attachment(props: AttachmentProps) { | ||
if (props.sensitive) { | ||
return ( | ||
<Blurhash | ||
hash={props.attachment.blurhash} | ||
height={144} | ||
width={144} | ||
className="max-w-full rounded-md" | ||
style={{ marginBottom: '2px' }} | ||
/> | ||
) | ||
} else { | ||
return ( | ||
<img | ||
src={props.attachment.preview_url} | ||
className="mb-2 max-w-full cursor-pointer" | ||
style={{ width: '144px', height: '144px' }} | ||
alt={props.attachment.description} | ||
title={props.attachment.description} | ||
/> | ||
) | ||
} | ||
} |
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