Skip to content

Commit

Permalink
Change encoding for share url
Browse files Browse the repository at this point in the history
  • Loading branch information
foyarash committed Feb 10, 2020
1 parent b336b8b commit 4267abd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"emotion-theming": "^10.0.27",
"lodash": "^4.17.15",
"lodash-es": "^4.17.15",
"lz-string": "^1.4.4",
"prism-react-renderer": "^1.0.2",
"react": "^16.12.0",
"react-color": "^2.18.0",
Expand Down Expand Up @@ -63,6 +64,7 @@
},
"devDependencies": {
"@types/lodash": "^4.14.149",
"@types/lz-string": "^1.3.33",
"@types/prettier": "^1.19.0",
"@types/react-color": "^3.0.1",
"@types/react-redux": "^7.1.7",
Expand Down
8 changes: 5 additions & 3 deletions src/utils/share.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as LZString from 'lz-string'

export const createShareUrl = (components: IComponents) =>
`${document.location.host}/?share=${btoa(
unescape(encodeURIComponent(JSON.stringify(components))),
`${document.location.host}/?share=${LZString.compressToEncodedURIComponent(
JSON.stringify(components),
)}`

export const decodeShareUrl = (): IComponents | null => {
Expand All @@ -9,7 +11,7 @@ export const decodeShareUrl = (): IComponents | null => {
const sharedData = searchParams.get('share')

if (sharedData) {
return JSON.parse(decodeURIComponent(escape(atob(sharedData))))
return JSON.parse(LZString.decompressFromEncodedURIComponent(sharedData))
}
} catch (e) {
console.log(e)
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,11 @@
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.149.tgz#1342d63d948c6062838fbf961012f74d4e638440"
integrity sha512-ijGqzZt/b7BfzcK9vTrS6MFljQRPn5BFWOx8oE0GYxribu6uV+aA9zZuXI1zc/etK9E8nrgdoF2+LgUw7+9tJQ==

"@types/lz-string@^1.3.33":
version "1.3.33"
resolved "https://registry.yarnpkg.com/@types/lz-string/-/lz-string-1.3.33.tgz#de2d6105ea7bcaf67dd1d9451d580700d30473fc"
integrity sha512-yWj3OnlKlwNpq9+Jh/nJkVAD3ta8Abk2kIRpjWpVkDlAD43tn6Q6xk5hurp84ndcq54jBDBGCD/WcIR0pspG0A==

"@types/minimatch@*", "@types/minimatch@3.0.3", "@types/minimatch@^3.0.3":
version "3.0.3"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
Expand Down

0 comments on commit 4267abd

Please sign in to comment.