Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@
"react": "^17.0.1"
},
"devDependencies": {
"@babel/cli": "^7.11.6",
"@babel/core": "^7.11.6",
"@babel/cli": "^7.25.9",
"@babel/core": "^7.26.0",
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/plugin-proposal-object-rest-spread": "^7.11.0",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/preset-env": "^7.11.5",
"@babel/preset-env": "^7.26.0",
"@babel/preset-react": "^7.10.4",
"@babel/preset-typescript": "^7.13.0",
"@types/enzyme": "^3.10.8",
"@types/enzyme-adapter-react-16": "^1.0.6",
"@types/jest": "^26.0.23",
"@types/jest": "^29.7.00",
"@types/node": "^20.10.3",
"@types/react": "^17.0.50",
"@types/react-dom": "^17.0.17",
Expand Down
10 changes: 8 additions & 2 deletions src/components/share_buttons/link_button.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { LinkIcon } from '../../assets/icons'
import { copyToClipboard, toQuery } from '../../helpers/sharing_helper'
import { addParamsToUrl, copyToClipboard } from '../../helpers/sharing_helper'
import { BaseShareActionArgs, buildShareButtonComponent } from './base'

export const linkAction = ({ shareUrl, utmParams }: BaseShareActionArgs) => {
copyToClipboard(`${shareUrl}${toQuery(utmParams || {})}`)
// if shareUrl
// const urlWithParams = new URL(shareUrl)
// for (const key in utmParams) {
// urlWithParams.searchParams.append(key, utmParams[key])
// }
// copyToClipboard(`${shareUrl}${toQuery(utmParams || {})}`)
copyToClipboard(addParamsToUrl(shareUrl, utmParams || {}))
}

export const LinkButton = buildShareButtonComponent({
Expand Down
8 changes: 8 additions & 0 deletions src/helpers/sharing_helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ export const toQuery = (object: Record<string, any>) => {
return searchParams ? `?${searchParams}` : ''
}

export const addParamsToUrl = (oldUrl: string, params: Record<string, any>) => {
const newUrl = new URL(oldUrl)
for (const [key, value] of params.entries()) {
newUrl.searchParams.append(key, value)
}
return newUrl.href
}

export const encodedShareURL = (url: string, utmParams?: Record<string, any>) =>
encodeURIComponent(url + toQuery(utmParams || {}))

Expand Down
Loading