Skip to content
Merged
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
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
],
"dependencies": {
"react": "16.8.5",
"react-dom": "16.8.5",
"url-search-params-polyfill": "^5.1.0"
"react-dom": "16.8.5"
},
"scripts": {
"start": "react-scripts-ts start",
Expand Down
20 changes: 14 additions & 6 deletions src/components/miniapp/MiniAppUrlsSelection.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { currentUrlMatchesRegexp } from './urlUtils';
import { appendUrlSearch, currentUrlMatchesRegexp } from './urlUtils';

export interface Props {
component: React.ComponentType;
Expand All @@ -16,11 +16,19 @@ export function MiniAppUrlsSelection({component: Component, urlRegexp, urlsByLab

return (
<div>
{Object.keys(urlsByLabel).map(label => (
<div>
<a href={urlsByLabel[label]}>{label}</a>
</div>
))}
{Object.keys(urlsByLabel).map(label => {
const url = urlsByLabel[label];
return (
<div key={label}>
<a href={url} onClick={(e) => selectUrl(e, url)}>{label}</a>
</div>
);
})}
</div>
);

function selectUrl(e: React.MouseEvent<HTMLElement>, url: string) {
e.preventDefault();
document.location.href = appendUrlSearch(url, document.location.search);
}
}
8 changes: 8 additions & 0 deletions src/components/miniapp/urlUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { appendUrlSearch } from './urlUtils';

describe('url utils', () => {
it('append url search', () => {
expect(appendUrlSearch('/just/path', '?a=2&b=3')).toEqual('/just/path?a=2&b=3');
expect(appendUrlSearch('/just/path?c=3', '?a=2')).toEqual('/just/path?c=3&a=2');
});
});
5 changes: 5 additions & 0 deletions src/components/miniapp/urlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ export function currentUrl() {

export function currentUrlMatchesRegexp(urlRegexp: RegExp) {
return urlRegexp.test(currentUrl());
}

export function appendUrlSearch(originalUrl: string, search: string) {
const hasSearch = originalUrl.indexOf('?') !== -1;
return originalUrl + (hasSearch ? '&' : '?') + search.replace('?', '');
}
2 changes: 0 additions & 2 deletions src/components/viewer/ComponentViewerStateCreator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'url-search-params-polyfill';

import { ComponentViewerState } from './ComponentViewerState';
import { Registry, Registries } from '../';
import { DemoEntryAndRegistry } from '../registry/DemoEntryAndRegistry';
Expand Down