diff --git a/webclient/src/Classes.js b/webclient/src/Classes.js
index f5a3143..541dde9 100644
--- a/webclient/src/Classes.js
+++ b/webclient/src/Classes.js
@@ -48,14 +48,17 @@ function ClassTable(props) {
);
};
+let classesCache = false;
+
export function Classes(props) {
- const [classes, setClasses] = useState(false);
+ const [classes, setClasses] = useState(classesCache);
const { token } = props;
useEffect(() => {
requester('/sessions/', 'GET', token)
.then(res => {
setClasses(res.results);
+ classesCache = res.results;
})
.catch(err => {
console.log(err);
diff --git a/webclient/src/Courses.js b/webclient/src/Courses.js
index b09648c..8609533 100644
--- a/webclient/src/Courses.js
+++ b/webclient/src/Courses.js
@@ -8,14 +8,17 @@ import { NotFound, PleaseLogin } from './Misc.js';
import { InstructorCourseList, InstructorCourseDetail } from './InstructorCourses.js';
import { InstructorClassList } from './InstructorClasses.js';
+let courseCache = false;
+
export function Courses(props) {
- const [courses, setCourses] = useState(false);
+ const [courses, setCourses] = useState(courseCache);
const { token, user } = props;
useEffect(() => {
requester('/courses/', 'GET', token)
.then(res => {
setCourses(res.results);
+ courseCache = res.results;
})
.catch(err => {
console.log(err);
diff --git a/webclient/src/ManageScroll.js b/webclient/src/ManageScroll.js
new file mode 100644
index 0000000..ded7bec
--- /dev/null
+++ b/webclient/src/ManageScroll.js
@@ -0,0 +1,44 @@
+import React, { useState, useEffect, useReducer, useContext } from 'react';
+import { BrowserRouter as Router, Switch, Route, Link, useParams, useHistory } from 'react-router-dom';
+
+let scrollPositions = {};
+let timeout = null;
+
+export function ManageScroll() {
+ const history = useHistory();
+
+ const scrollListener = () => {
+ if (timeout) {
+ window.cancelAnimationFrame(timeout);
+ }
+
+ timeout = window.requestAnimationFrame(() => {
+ const key = history.location.key;
+ if (key in scrollPositions) {
+ scrollPositions[key] = window.scrollY;
+ }
+ });
+ };
+
+ useEffect(() => {
+ window.addEventListener('scroll', scrollListener);
+ return () => {
+ window.removeEventListener('scroll', scrollListener);
+ }
+ }, []);
+
+ useEffect(() => {
+ const key = history.location.key;
+
+ if (key in scrollPositions) {
+ window.scrollTo(0, scrollPositions[key]);
+ } else {
+ window.scrollTo(0, 0);
+ scrollPositions[key] = 0;
+ }
+ }, [history.location]);
+
+ return (
+ null
+ );
+};
diff --git a/webclient/src/Members.js b/webclient/src/Members.js
index b057992..3ab28a9 100644
--- a/webclient/src/Members.js
+++ b/webclient/src/Members.js
@@ -49,13 +49,16 @@ export function MembersDropdown(props) {
);
};
+let searchCache = '';
+
export function Members(props) {
const [response, setResponse] = useState(false);
- const searchDefault = {seq: 0, q: ''};
+ const searchDefault = {seq: 0, q: searchCache};
const [search, setSearch] = useState(searchDefault);
const { token } = props;
useEffect(() => {
+ searchCache = search.q;
requester('/search/', 'POST', token, search)
.then(res => {
if (!search.seq || res.seq > response.seq) {
@@ -82,7 +85,7 @@ export function Members(props) {
{search.q.length ?