diff options
Diffstat (limited to 'vnext/src')
-rw-r--r-- | vnext/src/App.js | 7 | ||||
-rw-r--r-- | vnext/src/api/index.js | 8 | ||||
-rw-r--r-- | vnext/src/index.js | 9 |
3 files changed, 15 insertions, 9 deletions
diff --git a/vnext/src/App.js b/vnext/src/App.js index 765697ab..ccdae78e 100644 --- a/vnext/src/App.js +++ b/vnext/src/App.js @@ -16,7 +16,7 @@ import Post from './ui/Post'; import Thread from './ui/Thread'; import Login from './ui/Login'; -import cookie from 'react-cookies'; +import { useCookies } from 'react-cookie'; import { me } from './api'; @@ -27,12 +27,13 @@ const elClassTop = 'content--top'; export default function App() { let contentRef = useRef(null); + const [cookie, setCookie] = useCookies(['hash']); useEffect(() => { svg4everybody(); let params = qs.parse(window.location.search.substring(1)); if (params.hash) { - cookie.save('hash', params.hash, { path: '/' }); + setCookie('hash', params.hash, { path: '/' }); let retpath = params.retpath || `${window.location.protocol}//${window.location.host}${window.location.pathname}`; window.history.replaceState({}, document.title, retpath); } @@ -96,7 +97,7 @@ export default function App() { }; }); }, [x, y, setScrollState]); - const [hash, setHash] = useState(cookie.load('hash')); + const [hash, setHash] = useState(cookie.hash); const [eventSource, setEventSource] = /** @param EventSource? */ useState({}); diff --git a/vnext/src/api/index.js b/vnext/src/api/index.js index d5fb6ba7..2392bfd0 100644 --- a/vnext/src/api/index.js +++ b/vnext/src/api/index.js @@ -1,5 +1,5 @@ import axios from 'axios'; -import cookies from 'react-cookies'; +import Cookies from 'universal-cookie'; const apiBaseUrl = 'https://juick.com'; @@ -71,8 +71,9 @@ const client = axios.create({ baseURL: apiBaseUrl }); client.interceptors.request.use(config => { + let cookies = new Cookies(); config.params = Object.assign(config.params || {}, { - hash: cookies.load('hash') + hash: cookies.get('hash') }); return config; }); @@ -84,6 +85,7 @@ client.interceptors.request.use(config => { * @return {Promise<SecureUser, Error>} me object */ export function me(username = '', password = '') { + let cookies = new Cookies(); return new Promise((resolve, reject) => { client.get('/api/me', { headers: username ? { @@ -91,7 +93,7 @@ export function me(username = '', password = '') { } : {} }).then(response => { let visitor = response.data; - cookies.save('hash', visitor.hash, { path: '/' }); + cookies.set('hash', visitor.hash, { path: '/' }); resolve(visitor); }).catch(reason => { cookies.remove('hash', { path: '/'}); diff --git a/vnext/src/index.js b/vnext/src/index.js index 0037c2a5..c9b9373a 100644 --- a/vnext/src/index.js +++ b/vnext/src/index.js @@ -1,6 +1,7 @@ import React, { lazy, Suspense } from 'react'; import ReactDOM from 'react-dom'; import { BrowserRouter } from 'react-router-dom'; +import { CookiesProvider } from 'react-cookie'; import './index.css'; @@ -17,9 +18,11 @@ const Juick = lazy(() => import('./App')); const JuickApp = () => ( <React.StrictMode> <Suspense fallback={LoadingView()}> - <BrowserRouter> - <Juick /> - </BrowserRouter> + <CookiesProvider> + <BrowserRouter> + <Juick /> + </BrowserRouter> + </CookiesProvider> </Suspense> </React.StrictMode> ); |