Skip to content

Commit

Permalink
Merge pull request #728 from italia/feature/url_fragments
Browse files Browse the repository at this point in the history
URL Fragments instead of Path params.
  • Loading branch information
mfortini authored Oct 2, 2024
2 parents a2939ad + ccb737d commit 651000e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/ShowButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const ShowButton = () => {
if (isDocumentTextTooLong(documentText)) {
alert('Snippet is too long.');
} else {
const url = `${window.location.origin}${window.location.pathname}?text=${b64url_encode(documentText)}`;
const url = `${window.location.origin}${window.location.pathname}#text=${b64url_encode(documentText)}`;
if (window.navigator.clipboard) {
window.navigator.clipboard.writeText(url).then(() => {
alert('Snippet url copied to clipboard!');
Expand Down
8 changes: 5 additions & 3 deletions src/redux/reducers/documentReducer.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { FOCUS_DOCUMENT_LINE, SET_DOCUMENT_URL, SET_DOCUMENT_TEXT } from '../actionTypes.js';
import { DEFAULT_DOCUMENT_URL } from '../../utils.mjs';

const queryParams = new URLSearchParams(window.location.search);
// Replace query string with fragment
const hashParams = new URLSearchParams(window.location.hash.substring(1)); // Get params from fragment

const initialState = {
focusLine: null,
text: null,
textParameter: queryParams.get('text') || null,
url: queryParams.get('text') ? null : queryParams.get('url') || DEFAULT_DOCUMENT_URL,
textParameter: hashParams.get('text') || null, // Get 'text' from fragment
url: hashParams.get('text') ? null : hashParams.get('url') || DEFAULT_DOCUMENT_URL, // Get 'url' from fragment or use default
};

export default function (state = initialState, action) {
Expand Down

0 comments on commit 651000e

Please sign in to comment.