Untitled

mail@pastecode.io avatar
unknown
plain_text
11 days ago
2.1 kB
2
Indexable
Never
// src/store/fileManager.ts
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { Client } from "ysftp-web-sdk";

interface FormValues {
  ip: string;
  port: number;
  username: string;
  password: string;
}

interface FileManagerState {
  leftClient: Client | null;
  rightClient: Client | null;
  leftPageClientValue: FormValues;
  rightPageClientValue: FormValues;
  leftPagePath: string;
  rightPagePath: string;
}

const initialState: FileManagerState = {
  leftClient: null,
  rightClient: null,
  leftPageClientValue: {
    ip: "",
    port: 0,
    username: "",
    password: "",
  },
  rightPageClientValue: {
    ip: "",
    port: 0,
    username: "",
    password: "",
  },
  leftPagePath: "/",
  rightPagePath: "/",
};

const fileManagerSlice = createSlice({
  name: "fileManager",
  initialState,
  reducers: {
    setleftClient: (
      state: { leftClient: Client | null },
      action: PayloadAction<Client | null>
    ) => {
      state.leftClient = action.payload;
    },
    setrightClient: (
      state: { leftClient: Client | null },
      action: PayloadAction<Client | null>
    ) => {
      state.leftClient = action.payload;
    },
    setLeftPageClientValue: (
      state: { leftPageClientValue: FormValues },
      action: PayloadAction<FormValues>
    ) => {
      state.leftPageClientValue = action.payload;
    },
    setRightPageClientValue: (
      state: { rightPageClientValue: FormValues },
      action: PayloadAction<FormValues>
    ) => {
      state.rightPageClientValue = action.payload;
    },
    setleftPagePath: (
      state: { leftPagePath: string },
      action: PayloadAction<string>
    ) => {
      state.leftPagePath = action.payload;
    },
    setrightPagePath: (
      state: { leftPagePath: string },
      action: PayloadAction<string>
    ) => {
      state.leftPagePath = action.payload;
    },
  },
});

export const { setLeftPageClientValue, setRightPageClientValue } =
  fileManagerSlice.actions;
export default fileManagerSlice.reducer;
Leave a Comment