-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: mkljczk <[email protected]>
- Loading branch information
Showing
1 changed file
with
24 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,34 @@ | ||
import React from 'react'; | ||
import { Redirect, useLocation } from 'react-router-dom'; | ||
import React, { useEffect } from 'react'; | ||
import { useHistory, useLocation } from 'react-router-dom'; | ||
|
||
import { openComposeWithText } from 'pl-fe/actions/compose'; | ||
import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch'; | ||
|
||
const Share = () => { | ||
const Share: React.FC = () => { | ||
const dispatch = useAppDispatch(); | ||
const history = useHistory(); | ||
|
||
const { search } = useLocation(); | ||
const params = new URLSearchParams(search); | ||
|
||
const text = [ | ||
params.get('title'), | ||
params.get('text'), | ||
params.get('url'), | ||
] | ||
.filter(v => v) | ||
.join('\n\n'); | ||
|
||
if (text) { | ||
dispatch(openComposeWithText('compose-modal', text)); | ||
} | ||
|
||
return ( | ||
<Redirect to='/' /> | ||
); | ||
|
||
useEffect(() => { | ||
const params = new URLSearchParams(search); | ||
|
||
const text = [ | ||
params.get('title'), | ||
params.get('text'), | ||
params.get('url'), | ||
] | ||
.filter(v => v) | ||
.join('\n\n'); | ||
|
||
if (text) { | ||
dispatch(openComposeWithText('compose-modal', text)); | ||
} | ||
|
||
history.replace('/'); | ||
}); | ||
|
||
return null; | ||
}; | ||
|
||
export { Share as default }; |