Updated design of announced Notes and Notes containing links

- Announced (reposted) Notes show information about both the Actor that
created the Note, and the Actor that Announced it
- The content of notes now keeps the formatting and links are clickable
and shown in different color

Co-authored-by: Djordje Vlaisavljevic <dzvlais@gmail.com>
This commit is contained in:
Fabien 'egg' O'Carroll 2024-08-05 18:07:03 +07:00 committed by GitHub
parent 779f9d1923
commit 5376bd52c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 49 additions and 20 deletions

View File

@ -4,7 +4,7 @@ import articleBodyStyles from './articleBodyStyles';
import getUsername from '../utils/get-username'; import getUsername from '../utils/get-username';
import {ActivityPubAPI} from '../api/activitypub'; import {ActivityPubAPI} from '../api/activitypub';
import {ActorProperties, ObjectProperties} from '@tryghost/admin-x-framework/api/activitypub'; import {ActorProperties, ObjectProperties} from '@tryghost/admin-x-framework/api/activitypub';
import {Avatar, Button, ButtonGroup, Heading, List, ListItem, Page, SelectOption, SettingValue, ViewContainer, ViewTab} from '@tryghost/admin-x-design-system'; import {Avatar, Button, ButtonGroup, Heading, Icon, List, ListItem, Page, SelectOption, SettingValue, ViewContainer, ViewTab} from '@tryghost/admin-x-design-system';
import {useBrowseSite} from '@tryghost/admin-x-framework/api/site'; import {useBrowseSite} from '@tryghost/admin-x-framework/api/site';
import {useQuery} from '@tanstack/react-query'; import {useQuery} from '@tanstack/react-query';
import {useRouting} from '@tryghost/admin-x-framework/routing'; import {useRouting} from '@tryghost/admin-x-framework/routing';
@ -123,6 +123,7 @@ const ActivityPubComponent: React.FC = () => {
actor={activity.actor} actor={activity.actor}
layout={selectedOption.value} layout={selectedOption.value}
object={activity.object} object={activity.object}
type={activity.type}
/> />
</li> </li>
))} ))}
@ -167,6 +168,7 @@ const ActivityPubComponent: React.FC = () => {
actor={activity.actor} actor={activity.actor}
layout={selectedOption.value} layout={selectedOption.value}
object={activity.object} object={activity.object}
type={activity.object.type}
/> />
</li> </li>
))} ))}
@ -320,7 +322,7 @@ ${image &&
); );
}; };
const ObjectContentDisplay: React.FC<{actor: ActorProperties, object: ObjectProperties, layout: string }> = ({actor, object, layout}) => { const ObjectContentDisplay: React.FC<{actor: ActorProperties, object: ObjectProperties, layout: string, type: string }> = ({actor, object, layout, type}) => {
const parser = new DOMParser(); const parser = new DOMParser();
const doc = parser.parseFromString(object.content || '', 'text/html'); const doc = parser.parseFromString(object.content || '', 'text/html');
@ -392,27 +394,40 @@ const ObjectContentDisplay: React.FC<{actor: ActorProperties, object: ObjectProp
setTimeout(() => setIsClicked(false), 300); // Reset the animation class after 300ms setTimeout(() => setIsClicked(false), 300); // Reset the animation class after 300ms
}; };
let author = actor;
if (type === 'Announce' && object.type === 'Note') {
author = typeof object.attributedTo === 'object' ? object.attributedTo as ActorProperties : actor;
}
if (layout === 'feed') { if (layout === 'feed') {
return ( return (
<> <>
{object && ( {object && (
<div className='group/article relative flex cursor-pointer items-start gap-4 pt-4'> <div className='group/article relative cursor-pointer pt-4'>
<img className='z-10 w-9 rounded' src={actor.icon?.url}/> {(type === 'Announce' && object.type === 'Note') && <div className='z-10 mb-2 flex items-center gap-4 text-grey-700'>
<div className='border-1 z-10 -mt-1 flex flex-col items-start justify-between border-b border-b-grey-200 pb-4' data-test-activity> <div className='z-10 flex w-10 justify-end'><Icon colorClass='text-grey-700' name='reload' size={'sm'}></Icon></div>
<div className='relative z-10 flex w-full overflow-visible text-[1.5rem]'> <span className='z-10'>{actor.name} reposted</span>
<p className='mr-1 truncate whitespace-nowrap font-bold' data-test-activity-heading>{actor.name}</p> </div>}
<span className='truncate text-grey-700'>{getUsername(actor)}</span> <div className='flex items-start gap-4'>
<span className='whitespace-nowrap text-grey-700 before:mx-1 before:content-["·"]'>{timestamp}</span> <img className='z-10 w-10 rounded' src={author.icon?.url}/>
</div> <div className='border-1 z-10 -mt-1 flex flex-col items-start justify-between border-b border-b-grey-200 pb-4' data-test-activity>
<div className='relative z-10 w-full gap-4'> <div className='relative z-10 mb-2 flex w-full flex-col overflow-visible text-[1.5rem]'>
<div className='flex flex-col'> <span className='mr-1 truncate whitespace-nowrap font-bold' data-test-activity-heading>{author.name}</span>
{object.name && <Heading className='mb-1 leading-tight' level={4} data-test-activity-heading>{object.name}</Heading>} <div className='flex'>
<p className='text-pretty text-[1.5rem] text-grey-900'>{plainTextContent}</p> <span className='truncate text-grey-700'>{getUsername(author)}</span>
{/* <p className='text-pretty text-md text-grey-900'>{object.content}</p> */} <span className='whitespace-nowrap text-grey-700 before:mx-1 before:content-["·"]'>{timestamp}</span>
{renderAttachment()} </div>
<div className='mt-3 flex gap-2'> </div>
<Button className={`self-start text-grey-500 transition-all hover:text-grey-800 ${isClicked ? 'bump' : ''} ${isLiked ? 'ap-red-heart text-red *:!fill-red hover:text-red' : ''}`} hideLabel={true} icon='heart' id="like" size='md' unstyled={true} onClick={handleLikeClick}/> <div className='relative z-10 w-full gap-4'>
<span className={`text-grey-800 ${isLiked ? 'opacity-100' : 'opacity-0'}`}>1</span> <div className='flex flex-col'>
{object.name && <Heading className='mb-1 leading-tight' level={4} data-test-activity-heading>{object.name}</Heading>}
<div dangerouslySetInnerHTML={({__html: object.content})} className='ap-note-content text-pretty text-[1.5rem] text-grey-900'></div>
{/* <p className='text-pretty text-md text-grey-900'>{object.content}</p> */}
{renderAttachment()}
<div className='mt-3 flex gap-2'>
<Button className={`self-start text-grey-500 transition-all hover:text-grey-800 ${isClicked ? 'bump' : ''} ${isLiked ? 'ap-red-heart text-red *:!fill-red hover:text-red' : ''}`} hideLabel={true} icon='heart' id="like" size='md' unstyled={true} onClick={handleLikeClick}/>
<span className={`text-grey-800 ${isLiked ? 'opacity-100' : 'opacity-0'}`}>1</span>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -22,4 +22,17 @@ animation: bump 0.3s ease-in-out;
.ap-red-heart path { .ap-red-heart path {
fill: #F50B23; fill: #F50B23;
} }
.ap-note-content a {
color: rgb(236 72 153) !important;
}
.ap-note-content a:hover {
color: rgb(219 39 119) !important;
}
.ap-note-content p + p {
margin-top: 1.5rem !important;
}

View File

@ -0,0 +1 @@
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" id="Button-Refresh-Arrows--Streamline-Ultimate.svg" height="24" width="24"><desc>Button Refresh Arrows Streamline Icon: https://streamlinehq.com</desc><path d="m5.25 14.248 0 4.5 -4.5 0" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"></path><path d="m18.75 9.748 0 -4.5 4.5 0" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"></path><path d="M19.032 5.245A9.752 9.752 0 0 1 8.246 21" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"></path><path d="M4.967 18.751A9.753 9.753 0 0 1 15.754 3" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"></path></svg>

After

Width:  |  Height:  |  Size: 819 B