Skip to content

Commit

Permalink
feat: Persist params on back click
Browse files Browse the repository at this point in the history
  • Loading branch information
Devil7DK committed Sep 23, 2023
1 parent e9a8fbc commit 7d5a8b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
10 changes: 9 additions & 1 deletion src/pages/Filters/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import './Filters.scss';
import { useState } from 'react';
import { IFilterData, IResponseData } from '../../interfaces';
import axios from 'axios';
import { useNavigate } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';
import { useFilterState } from '../../utils';

export const Filters: React.FC = () => {
const navigate = useNavigate();
const location = useLocation();

const [loading, setLoading] = useState<boolean>(false);
const [token, setToken] = useState<string | null>(null);
Expand Down Expand Up @@ -108,6 +109,13 @@ export const Filters: React.FC = () => {
)
.then((response) => {
if (response.data.success) {
if (window.localStorage && location.search) {
window.localStorage.setItem(
'params',
location.search
);
}

navigate('/names');
}
})
Expand Down
21 changes: 12 additions & 9 deletions src/pages/Names/Names.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ export const Names: React.FC = () => {
const [loading, setLoading] = useState(false);
const [exporting, setExporting] = useState(false);

const onExport = () => {
setExporting(true);
axios
.get('/api/export')
.then((response) => saveAs(response.data, 'Baby Names.pdf'))
.finally(() => setExporting(false));
};

useEffect(() => {
setLoading(true);
axios
Expand All @@ -58,7 +50,18 @@ export const Names: React.FC = () => {
return (
<div className='names-container'>
<Card className='top-container'>
<Button onClick={() => navigate('/')}>Back</Button>
<Button
onClick={() =>
navigate(
window.localStorage &&
window.localStorage.getItem('params')
? `/${window.localStorage.getItem('params')}`
: '/'
)
}
>
Back
</Button>
<div>
<div>Total Names: {total}</div>
<Button
Expand Down

0 comments on commit 7d5a8b6

Please sign in to comment.