Skip to content

Commit

Permalink
feat: improve share on x to include link with screenshot of image
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Feb 2, 2024
1 parent e0c5ffb commit 7ce33c3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
48 changes: 27 additions & 21 deletions src/components/leaderboard/ProgressModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function ProgressPanel({

const spaceHandleOrId = profile?.struct.handle || profile?.id

const shareOnPolkaverse = async () => {
const generateImage = async (onSuccess: (image: string) => void) => {
const element = document.getElementById('progress-image')
if (!element) return

Expand Down Expand Up @@ -208,12 +208,7 @@ function ProgressPanel({
if (!cid) throw new Error('Failed to save image to IPFS')

progressModalStorage.close()
window.open(
fullUrl(
`${defaultSpaceIdToPost}/posts/new?image=${encodeURIComponent(resolveIpfsUrl(cid))}`,
),
'_blank',
)
onSuccess(resolveIpfsUrl(cid))
} catch (err: any) {
controlledMessage({
message: 'Failed to generate reward image',
Expand All @@ -226,6 +221,30 @@ function ProgressPanel({
})
}

const shareOnPolkaverse = () => {
generateImage(image => {
window.open(
fullUrl(`${defaultSpaceIdToPost}/posts/new?image=${encodeURIComponent(image)}`),
'_blank',
)
})
}

const shareOnX = () => {
generateImage(image => {
openNewWindow(
twitterShareUrl(
spaceHandleOrId
? `/${spaceHandleOrId}?customImage=${encodeURIComponent(image)}`
: `/accounts/${myAddress}`,
`I earned #SUB ${
isUsingLastWeekData ? 'last week for my activity' : 'yesterday'
} on @SubsocialChain! 🥳\n\nFollow me here and join The Creator Economy!`,
),
)
})
}

return (
<>
<DiamondIcon className={styles.DiamondIcon} />
Expand Down Expand Up @@ -283,20 +302,7 @@ function ProgressPanel({
className='GapNormal mt-4'
style={{ display: 'grid', gridTemplateColumns: defaultSpaceIdToPost ? '1fr 1fr' : '1fr' }}
>
<Button
type='default'
size='large'
onClick={() =>
openNewWindow(
twitterShareUrl(
spaceHandleOrId ? `/${spaceHandleOrId}` : `/accounts/${myAddress}`,
`I earned #SUB ${
isUsingLastWeekData ? 'last week for my activity' : 'yesterday'
} on @SubsocialChain! 🥳\n\nFollow me here and join The Creator Economy!`,
),
)
}
>
<Button type='default' size='large' loading={loading} onClick={() => shareOnX()}>
Share on X
</Button>
{defaultSpaceIdToPost && (
Expand Down
11 changes: 8 additions & 3 deletions src/components/spaces/ViewSpacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ import { loadSpaceOnNextReq } from './helpers/loadSpaceOnNextReq'
import { ViewSpace } from './ViewSpace'
import { ViewSpaceProps } from './ViewSpaceProps'

type Props = ViewSpaceProps & HasStatusCode
type Props = ViewSpaceProps &
HasStatusCode & {
customImage?: string
}

const InnerViewSpacePage: FC<Props> = props => {
const myAddress = useMyAddress()
const { spaceData } = props
const { spaceData, customImage } = props

useFetchMyPermissionsBySpaceId(spaceData?.id)

Expand All @@ -45,7 +48,7 @@ const InnerViewSpacePage: FC<Props> = props => {
meta={{
title,
desc: `Latest news and updates from ${name} on Polkaverse.`,
image,
image: customImage || image,
canonical: spaceUrl(spaceData.struct),
}}
withSidebar
Expand Down Expand Up @@ -89,6 +92,7 @@ getInitialPropsWithRedux(ViewSpacePage, async props => {
const sortedPostIds = descSort(postIds)

const pageIds = getPageOfIds(sortedPostIds, query)
const customImage = query.customImage as string | undefined

await dispatch(
fetchPosts({
Expand All @@ -106,6 +110,7 @@ getInitialPropsWithRedux(ViewSpacePage, async props => {
spaceData: data,
posts,
postIds: sortedPostIds,
customImage,
}
})

Expand Down

0 comments on commit 7ce33c3

Please sign in to comment.