🔧 Tooling for resumable socket.io sessions

This commit is contained in:
2023-07-27 11:08:51 -07:00
parent 26fdb6d3a4
commit 11ef9e6e2a
7 changed files with 36 additions and 24 deletions

View File

@@ -33,7 +33,6 @@ export const getWeeklyPullList = (options) => async (dispatch) => {
dispatch({ dispatch({
type: CV_WEEKLY_PULLLIST_CALL_IN_PROGRESS, type: CV_WEEKLY_PULLLIST_CALL_IN_PROGRESS,
}); });
await cachedAxios(`${COMICVINE_SERVICE_URI}/getWeeklyPullList`, { await cachedAxios(`${COMICVINE_SERVICE_URI}/getWeeklyPullList`, {
method: "get", method: "get",
params: options, params: options,

View File

@@ -40,7 +40,7 @@ import { success } from "react-notification-system-redux";
import { isNil, map } from "lodash"; import { isNil, map } from "lodash";
export const getServiceStatus = (serviceName?: string) => async (dispatch) => { export const getServiceStatus = (serviceName?: string) => async dispatch => {
axios axios
.request({ .request({
url: `${LIBRARY_SERVICE_BASE_URI}/getHealthInformation`, url: `${LIBRARY_SERVICE_BASE_URI}/getHealthInformation`,
@@ -91,9 +91,9 @@ export const fetchComicBookMetadata = () => async (dispatch) => {
// }), // }),
// ); // );
dispatch({ dispatch({
type: "EMIT_SOCKET_EVENT", type: LS_IMPORT,
meta: { remote: true }, meta: { remote: true },
data: { gym: "asas" }, data: {},
}); });
}; };
export const toggleImportQueueStatus = (options) => async (dispatch) => { export const toggleImportQueueStatus = (options) => async (dispatch) => {

View File

@@ -19,7 +19,7 @@ import {
} from "../context/AirDCPPSocket"; } from "../context/AirDCPPSocket";
import { SocketIOProvider } from "../context/SocketIOContext"; import { SocketIOProvider } from "../context/SocketIOContext";
import socketIOConnectionInstance from "../shared/socket.io/instance"; import socketIOConnectionInstance from "../shared/socket.io/instance";
import { isEmpty, isUndefined } from "lodash"; import { isEmpty, isNil, isUndefined } from "lodash";
import { import {
AIRDCPP_DOWNLOAD_PROGRESS_TICK, AIRDCPP_DOWNLOAD_PROGRESS_TICK,
LS_SINGLE_IMPORT, LS_SINGLE_IMPORT,
@@ -97,13 +97,23 @@ const AirDCPPSocketComponent = (): ReactElement => {
return <></>; return <></>;
}; };
export const App = (): ReactElement => { export const App = (): ReactElement => {
const dispatch = useDispatch();
useEffect(() => { useEffect(() => {
// Listen for the sessionInitialized event // Check if there is a sessionId in localStorage
socketIOConnectionInstance.on("sessionInitialized", (sessionId) => { const sessionId = localStorage.getItem("sessionId");
console.log(sessionId); if (!isNil(sessionId)) {
// Store the session ID in Redux state // Resume the session
// initSession(sessionId); dispatch({
}); type: "RESUME_SESSION",
meta: { remote: true },
data: { sessionId },
});
} else {
// Inititalize the session and persist the sessionId to localStorage
socketIOConnectionInstance.on("sessionInitialized", (sessionId) => {
localStorage.setItem("sessionId", sessionId);
});
}
}, []); }, []);
return ( return (
<SocketIOProvider socket={socketIOConnectionInstance}> <SocketIOProvider socket={socketIOConnectionInstance}>

View File

@@ -48,7 +48,9 @@ export const ComicInfoXML = (data): ReactElement => {
<dd> <dd>
<span className="is-size-7">{json.notes[0]}</span> <span className="is-size-7">{json.notes[0]}</span>
</dd> </dd>
<dd className="mt-1 mb-1">{json.summary[0]}</dd> <dd className="mt-1 mb-1">
{!isUndefined(json.summary) && json.summary[0]}
</dd>
</dl> </dl>
</div> </div>
); );

View File

@@ -21,7 +21,7 @@ export const PullList = ({ issues }: PullListProps): ReactElement => {
useEffect(() => { useEffect(() => {
dispatch( dispatch(
getWeeklyPullList({ getWeeklyPullList({
startDate: "2023-5-25", startDate: "2023-7-25",
pageSize: "15", pageSize: "15",
currentPage: "1", currentPage: "1",
}), }),

View File

@@ -15,7 +15,7 @@ export const PullList = (): ReactElement => {
useEffect(() => { useEffect(() => {
dispatch( dispatch(
getWeeklyPullList({ getWeeklyPullList({
startDate: "2022-11-15", startDate: "2023-7-28",
pageSize: "15", pageSize: "15",
currentPage: "1", currentPage: "1",
}), }),
@@ -109,15 +109,15 @@ export const PullList = (): ReactElement => {
{!isNil(pullListComics) && ( {!isNil(pullListComics) && (
<div> <div>
<div className="library"> <div className="library">
<T2Table <T2Table
sourceData={pullListComics} sourceData={pullListComics}
columns={columnData} columns={columnData}
totalPages={pullListComics.length} totalPages={pullListComics.length}
paginationHandlers={{ paginationHandlers={{
nextPage: nextPageHandler, nextPage: nextPageHandler,
previousPage: previousPageHandler, previousPage: previousPageHandler,
}} }}
/> />
</div> </div>
</div> </div>
)} )}

View File

@@ -1,9 +1,10 @@
import io from "socket.io-client"; import io from "socket.io-client";
import { SOCKET_BASE_URI } from "../../constants/endpoints"; import { SOCKET_BASE_URI } from "../../constants/endpoints";
const sessionId = localStorage.getItem("sessionId");
const socketIOConnectionInstance = io(SOCKET_BASE_URI, { const socketIOConnectionInstance = io(SOCKET_BASE_URI, {
transports: ["websocket"], transports: ["websocket"],
withCredentials: true, withCredentials: true,
query: { sessionId },
}); });
export default socketIOConnectionInstance; export default socketIOConnectionInstance;