❌ AirDCPP code cleaned up from App.tsx
This commit is contained in:
@@ -27,72 +27,8 @@ import {
|
|||||||
* 2. Handles errors in case the connection to AirDC++ is not established or terminated
|
* 2. Handles errors in case the connection to AirDC++ is not established or terminated
|
||||||
* @returns void
|
* @returns void
|
||||||
*/
|
*/
|
||||||
const AirDCPPSocketComponent = (): ReactElement => {
|
|
||||||
// const airDCPPConfiguration = useContext(AirDCPPSocketContext);
|
|
||||||
// const dispatch = useDispatch();
|
|
||||||
//
|
|
||||||
// useEffect(() => {
|
|
||||||
// const initializeAirDCPPEventListeners = async () => {
|
|
||||||
// if (
|
|
||||||
// !isUndefined(airDCPPConfiguration.airDCPPState) &&
|
|
||||||
// !isEmpty(airDCPPConfiguration.airDCPPState.settings) &&
|
|
||||||
// !isEmpty(airDCPPConfiguration.airDCPPState.socket)
|
|
||||||
// ) {
|
|
||||||
// await airDCPPConfiguration.airDCPPState.socket.addListener(
|
|
||||||
// "queue",
|
|
||||||
// "queue_bundle_added",
|
|
||||||
// async (data) => {
|
|
||||||
// console.log("JEMEN:", data);
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
// // download tick listener
|
|
||||||
// await airDCPPConfiguration.airDCPPState.socket.addListener(
|
|
||||||
// `queue`,
|
|
||||||
// "queue_bundle_tick",
|
|
||||||
// async (downloadProgressData) => {
|
|
||||||
// dispatch({
|
|
||||||
// type: AIRDCPP_DOWNLOAD_PROGRESS_TICK,
|
|
||||||
// downloadProgressData,
|
|
||||||
// });
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
// // download complete listener
|
|
||||||
// await airDCPPConfiguration.airDCPPState.socket.addListener(
|
|
||||||
// `queue`,
|
|
||||||
// "queue_bundle_status",
|
|
||||||
// async (bundleData) => {
|
|
||||||
// let count = 0;
|
|
||||||
// if (bundleData.status.completed && bundleData.status.downloaded) {
|
|
||||||
// // dispatch the action for raw import, with the metadata
|
|
||||||
// if (count < 1) {
|
|
||||||
// console.log(`[AirDCPP]: Download complete.`);
|
|
||||||
// dispatch({
|
|
||||||
// type: LS_SINGLE_IMPORT,
|
|
||||||
// meta: { remote: true },
|
|
||||||
// data: bundleData,
|
|
||||||
// });
|
|
||||||
// count += 1;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
// console.log(
|
|
||||||
// "[AirDCPP]: Listener registered - listening to queue bundle download ticks",
|
|
||||||
// );
|
|
||||||
// console.log(
|
|
||||||
// "[AirDCPP]: Listener registered - listening to queue bundle changes",
|
|
||||||
// );
|
|
||||||
// console.log(
|
|
||||||
// "[AirDCPP]: Listener registered - listening to transfer completion",
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// initializeAirDCPPEventListeners();
|
|
||||||
// }, [airDCPPConfiguration]);
|
|
||||||
return <></>;
|
|
||||||
};
|
|
||||||
export const App = (): ReactElement => {
|
export const App = (): ReactElement => {
|
||||||
console.log("randitva");
|
|
||||||
// useEffect(() => {
|
// useEffect(() => {
|
||||||
// // Check if there is a sessionId in localStorage
|
// // Check if there is a sessionId in localStorage
|
||||||
// const sessionId = localStorage.getItem("sessionId");
|
// const sessionId = localStorage.getItem("sessionId");
|
||||||
@@ -110,12 +46,7 @@ export const App = (): ReactElement => {
|
|||||||
// });
|
// });
|
||||||
// }
|
// }
|
||||||
// }, []);
|
// }, []);
|
||||||
return (
|
return <>{/* The rest of your application */}</>;
|
||||||
<>
|
|
||||||
{/* The rest of your application */}
|
|
||||||
{/* <AirDCPPSocketComponent /> */};
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default App;
|
export default App;
|
||||||
|
|||||||
@@ -6,18 +6,21 @@ import { useStore } from "../../../store/index";
|
|||||||
import { useShallow } from "zustand/react/shallow";
|
import { useShallow } from "zustand/react/shallow";
|
||||||
|
|
||||||
export const AirDCPPSettingsForm = (): ReactElement => {
|
export const AirDCPPSettingsForm = (): ReactElement => {
|
||||||
// const airDCPPSettings = useContext(AirDCPPSocketContext);
|
// cherry-picking selectors for:
|
||||||
|
// 1. initial values for the form
|
||||||
|
// 2. If initial values are present, get the socket information to display
|
||||||
const {
|
const {
|
||||||
airDCPPSocketConnected,
|
airDCPPSocketConnected,
|
||||||
disconnectionInfo,
|
airDCPPDisconnectionInfo,
|
||||||
socketConnectionInformation,
|
airDCPPSocketConnectionInformation,
|
||||||
airDCPPClientConfiguration,
|
airDCPPClientConfiguration,
|
||||||
} = useStore(
|
} = useStore(
|
||||||
useShallow((state) => ({
|
useShallow((state) => ({
|
||||||
airDCPPSocketConnected: state.airDCPPSocketConnected,
|
airDCPPSocketConnected: state.airDCPPSocketConnected,
|
||||||
disconnectionInfo: state.disconnectionInfo,
|
airDCPPDisconnectionInfo: state.airDCPPDisconnectionInfo,
|
||||||
airDCPPClientConfiguration: state.airDCPPClientConfiguration,
|
airDCPPClientConfiguration: state.airDCPPClientConfiguration,
|
||||||
socketConnectionInformation: state.socketConnectionInformation,
|
airDCPPSocketConnectionInformation:
|
||||||
|
state.airDCPPSocketConnectionInformation,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -44,8 +47,10 @@ export const AirDCPPSettingsForm = (): ReactElement => {
|
|||||||
formHeading={"Configure AirDC++"}
|
formHeading={"Configure AirDC++"}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{!isEmpty(socketConnectionInformation) ? (
|
{!isEmpty(airDCPPSocketConnectionInformation) ? (
|
||||||
<AirDCPPSettingsConfirmation settings={socketConnectionInformation} />
|
<AirDCPPSettingsConfirmation
|
||||||
|
settings={airDCPPSocketConnectionInformation}
|
||||||
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{!isEmpty(airDCPPClientConfiguration) ? (
|
{!isEmpty(airDCPPClientConfiguration) ? (
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import { isEmpty, isUndefined } from "lodash";
|
import { isEmpty } from "lodash";
|
||||||
import AirDCPPSocket from "../services/DcppSearchService";
|
import AirDCPPSocket from "../services/DcppSearchService";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
export const useStore = create((set, get) => ({
|
export const useStore = create((set, get) => ({
|
||||||
|
// AirDC++ state
|
||||||
airDCPPSocketConnected: false,
|
airDCPPSocketConnected: false,
|
||||||
disconnectionInfo: {},
|
airDCPPDisconnectionInfo: {},
|
||||||
airDCPPClientConfiguration: {},
|
airDCPPClientConfiguration: {},
|
||||||
socketConnectionInformation: {},
|
airDCPPSocketConnectionInformation: {},
|
||||||
setAirDCPPSocketConnectionStatus: () =>
|
setAirDCPPSocketConnectionStatus: () =>
|
||||||
set((value) => ({
|
set((value) => ({
|
||||||
airDCPPSocketConnected: value,
|
airDCPPSocketConnected: value,
|
||||||
@@ -15,6 +16,7 @@ export const useStore = create((set, get) => ({
|
|||||||
getAirDCPPConnectionStatus: () => {
|
getAirDCPPConnectionStatus: () => {
|
||||||
const airDCPPSocketConnectionStatus = get().airDCPPSocketConnected;
|
const airDCPPSocketConnectionStatus = get().airDCPPSocketConnected;
|
||||||
},
|
},
|
||||||
|
// Socket.io state
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const { getState, setState } = useStore;
|
const { getState, setState } = useStore;
|
||||||
@@ -44,11 +46,45 @@ const initializeAirDCPPSocket = async (configuration) => {
|
|||||||
airDCPPSocketConnected: false,
|
airDCPPSocketConnected: false,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
// AirDC++ Socket-related connection and post-connection
|
||||||
// Attempt connection
|
// Attempt connection
|
||||||
const socketConnectionInformation = await initializedAirDCPPSocket.connect();
|
const airDCPPSocketConnectionInformation =
|
||||||
|
await initializedAirDCPPSocket.connect();
|
||||||
setState({
|
setState({
|
||||||
socketConnectionInformation,
|
airDCPPSocketConnectionInformation,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Set up event listeners
|
||||||
|
initializedAirDCPPSocket.addListener(
|
||||||
|
`queue`,
|
||||||
|
"queue_bundle_tick",
|
||||||
|
async (downloadProgressData) => {
|
||||||
|
console.log(downloadProgressData);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
initializedAirDCPPSocket.addListener(
|
||||||
|
"queue",
|
||||||
|
"queue_bundle_added",
|
||||||
|
async (data) => {
|
||||||
|
console.log("JEMEN:", data);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
initializedAirDCPPSocket.addListener(
|
||||||
|
`queue`,
|
||||||
|
"queue_bundle_status",
|
||||||
|
async (bundleData) => {
|
||||||
|
let count = 0;
|
||||||
|
if (bundleData.status.completed && bundleData.status.downloaded) {
|
||||||
|
// dispatch the action for raw import, with the metadata
|
||||||
|
if (count < 1) {
|
||||||
|
console.log(`[AirDCPP]: Download complete.`);
|
||||||
|
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 1. get settings from mongo
|
// 1. get settings from mongo
|
||||||
|
|||||||
Reference in New Issue
Block a user