forked from TryGhost/Ghost
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored handleViewContent so it can be reused (TryGhost#21468)
ref https://linear.app/ghost/issue/AP-540/clicking-comment-icon-on-posts-and-likes-tabs-of-your-profile-doesnt - We want to open posts in the drawer from multiple views (Inbox, Profile etc.) and this change allows us to do so by pulling `handleViewContent` from `Inbox.tsx` into a utility function. At the same time, we’ve simplified the function so it uses less props to achieve the same functionality. - Also added a simple fix for scrolling the reply-box into view when opening a long `article` by clicking on the reply icon. We probably still need to figure out a more robust solution, because the height of the `iframe` and the fact it takes some time to load it sometimes gets in the way. Co-authored-by: Michael Barrett <mike@ghost.org>
- Loading branch information
Showing
5 changed files
with
73 additions
and
74 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
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,43 @@ | ||
import ArticleModal from '../components/feed/ArticleModal'; | ||
import NiceModal from '@ebay/nice-modal-react'; | ||
import {type Activity} from '../components/activities/ActivityItem'; | ||
|
||
export const handleViewContent = ( | ||
activity: Activity, | ||
focusReply = false, | ||
updateActivity: (id: string, updated: Partial<Activity>) => void = () => {} | ||
) => { | ||
const authorActor = getContentAuthor(activity); | ||
NiceModal.show(ArticleModal, { | ||
activityId: activity.id, | ||
object: activity.object, | ||
actor: authorActor, | ||
comments: Array.isArray(activity.object.replies) ? activity.object.replies : [], | ||
focusReply, | ||
updateActivity | ||
}); | ||
}; | ||
|
||
export const getContentAuthor = (activity: Activity) => { | ||
const actor = activity.actor; | ||
const attributedTo = activity.object.attributedTo; | ||
|
||
if (!attributedTo) { | ||
return actor; | ||
} | ||
|
||
if (typeof attributedTo === 'string') { | ||
return actor; | ||
} | ||
|
||
if (Array.isArray(attributedTo)) { | ||
const found = attributedTo.find(item => typeof item !== 'string'); | ||
if (found) { | ||
return found; | ||
} else { | ||
return actor; | ||
} | ||
} | ||
|
||
return attributedTo; | ||
}; |