From 8c6c916444cf53b422bc6525abcf096db140d6df Mon Sep 17 00:00:00 2001 From: subnub Date: Wed, 17 Jul 2024 22:11:32 -0400 Subject: [PATCH] started removing reducers --- src/components/Homepage/index.tsx | 7 - src/components/LoginPage/index.jsx | 4 +- src/components/MainSection/index.tsx | 4 - src/components/ShareMenu/ShareMenu.jsx | 47 -- src/components/ShareMenu/index.jsx | 218 ------- src/components/ShareModel/index.jsx | 594 ------------------ src/components/ShareModelWrapper/index.jsx | 24 - .../UploadOverlay/UploadOverlay.jsx | 23 - src/components/UploadOverlay/index.jsx | 61 -- src/store/configureStore.ts | 30 +- 10 files changed, 17 insertions(+), 995 deletions(-) delete mode 100644 src/components/ShareMenu/ShareMenu.jsx delete mode 100644 src/components/ShareMenu/index.jsx delete mode 100644 src/components/ShareModel/index.jsx delete mode 100644 src/components/ShareModelWrapper/index.jsx delete mode 100644 src/components/UploadOverlay/UploadOverlay.jsx delete mode 100644 src/components/UploadOverlay/index.jsx diff --git a/src/components/Homepage/index.tsx b/src/components/Homepage/index.tsx index ef50f02..7255676 100644 --- a/src/components/Homepage/index.tsx +++ b/src/components/Homepage/index.tsx @@ -2,15 +2,12 @@ import Header from "../Header"; import MainSection from "../MainSection"; import Uploader from "../Uploader"; import React from "react"; -import UploadOverlay from "../UploadOverlay"; import HomepageSpinner from "../HomepageSpinner"; import MobileContextMenuContainer from "../MobileContextMenu"; -import ShareModelWrapper from "../ShareModelWrapper"; import PhotoViewer from "../PhotoViewer"; import { useAppSelector } from "../../hooks/store"; const Homepage = () => { - const photoID = useAppSelector((state) => state.photoViewer.id); return (
@@ -20,12 +17,8 @@ const Homepage = () => {
- {photoID.length === 0 ? undefined : }
- - - ); }; diff --git a/src/components/LoginPage/index.jsx b/src/components/LoginPage/index.jsx index 325dbcd..d2d9371 100644 --- a/src/components/LoginPage/index.jsx +++ b/src/components/LoginPage/index.jsx @@ -32,9 +32,10 @@ class LoginPageContainer extends React.Component { } loginWithToken = async () => { + console.log("login with token"); const loginSuccessful = await this.props.dispatch(startLoginCheck()); const loginRedirectRoute = - this.props.location.state?.from?.pathname || this.props.currentRoute; + this.props.location.state?.from?.pathname || "/home"; if (loginSuccessful) { this.props.navigate(loginRedirectRoute); } @@ -250,7 +251,6 @@ const mapStateToProps = (state) => ({ id: state.auth.id, loginFailed: state.main.loginFailed, loginFailedCode: state.main.loginFailedCode, - currentRoute: state.routes.currentRoute, createNewAccount: state.main.createNewAccount, }); diff --git a/src/components/MainSection/index.tsx b/src/components/MainSection/index.tsx index 5d45f96..5947388 100644 --- a/src/components/MainSection/index.tsx +++ b/src/components/MainSection/index.tsx @@ -12,8 +12,6 @@ import PhotoViewerPopup from "../PhotoViewerPopup"; import FileInfoPopup from "../FileInfoPopup"; const MainSection = memo(() => { - const moverID = useAppSelector((state) => state.mover.id); - const showPopup = useAppSelector((state) => state.popupFile.showPopup); const selectedItem = useAppSelector((state) => state.selected.popupModal); const { isMedia } = useUtils(); return ( @@ -32,8 +30,6 @@ const MainSection = memo(() => { ) : undefined} - {moverID.length === 0 ? undefined : } -
diff --git a/src/components/ShareMenu/ShareMenu.jsx b/src/components/ShareMenu/ShareMenu.jsx deleted file mode 100644 index db3ee74..0000000 --- a/src/components/ShareMenu/ShareMenu.jsx +++ /dev/null @@ -1,47 +0,0 @@ -import React from "react"; - -const ShareMenu = React.forwardRef((props, ref) => { - - if (props.shareSelected === "") { - - return ( -
- -
- ) - - } else { - - return ( -
- - {props.shareSelected.metadata.link ? - -
- -
- -

{props.state.title}

-
- - -
- - : -
- - -

Or

- -
- } - -
- ) - - } - -}) - -export default ShareMenu \ No newline at end of file diff --git a/src/components/ShareMenu/index.jsx b/src/components/ShareMenu/index.jsx deleted file mode 100644 index 581e040..0000000 --- a/src/components/ShareMenu/index.jsx +++ /dev/null @@ -1,218 +0,0 @@ -import ShareMenu from "./ShareMenu"; -import {editFile} from "../../actions/files" -import {editSelectedItem, setShareSelected, editShareSelected} from "../../actions/selectedItem" -import env from "../../enviroment/envFrontEnd"; -import axios from "../../axiosInterceptor"; -import Swal from "sweetalert2" -import copy from "copy-text-to-clipboard"; -import {connect} from "react-redux"; -import React from "react"; - -const currentURL = env.url; - -class ShareMenuContainer extends React.Component { - - constructor(props) { - super(props); - - this.wrapperRef = React.createRef(); - - this.showingSwal = false; - - this.state = { - title: "No Link" - } - } - - handleClickOutside = (e) => { - - if (this.wrapperRef && !this.wrapperRef.current.contains(event.target) && !this.showingSwal) { - - this.props.dispatch(setShareSelected("")) - } - } - - hide = () => { - - this.props.dispatch(setShareSelected("")) - } - - componentWillUnmount = () => { - document.removeEventListener('mousedown', this.handleClickOutside); - } - - componentDidMount = () => { - document.addEventListener('mousedown', this.handleClickOutside); - } - - componentDidUpdate = () => { - if (!this.props.shareSelected.metadata) return; - const shareURL = this.props.shareSelected.metadata.drive ? this.props.shareSelected.metadata.link : `/download-page/${this.props.shareSelected._id}/${this.props.shareSelected.metadata.link}` - if (this.props.shareSelected.metadata.link && shareURL !== this.state.title) { - - this.setState(() => { - return { - title: shareURL - } - }) - } - } - - makePublic = () => { - - this.showingSwal = true; - - Swal.fire({ - title: 'Are you sure?', - text: "Making this public, will allow anyone to have access to it", - icon: 'warning', - showCancelButton: true, - confirmButtonColor: '#3085d6', - cancelButtonColor: '#d33', - confirmButtonText: 'Yes, make public' - }).then((result) => { - - this.showingSwal = false; - - if (result.value) { - - const url = this.props.shareSelected.metadata.drive ? `/file-service-google/make-public/${this.props.shareSelected._id}` : `/file-service/make-public/${this.props.shareSelected._id}`; - - axios.patch(url, undefined).then((results) => { - - this.props.dispatch(editFile(this.props.shareSelected._id,{"metadata": { - ...this.props.shareSelected.metadata, - link: results.data, - linkType: "public" - }})) - - this.props.dispatch(editSelectedItem({link: results.data, - linkType: "public"})) - - - this.props.dispatch(editShareSelected({"metadata": { - ...this.props.shareSelected.metadata, - link: results.data, - linkType: "public" - }})) - - const shareURL = this.props.shareSelected.metadata.drive ? results.data : `${currentURL}/download-page/${this.props.shareSelected._id}/${this.props.shareSelected.metadata.link}` - - this.setState(() => { - return { - title: shareURL - } - }) - - }).catch((err) => { - console.log(err) - }) - - - } - }) - } - - makeOne = () => { - - this.showingSwal = true; - - Swal.fire({ - title: 'Are you sure?', - text: "One time link, will allow anyone to access this file once", - icon: 'warning', - showCancelButton: true, - confirmButtonColor: '#3085d6', - cancelButtonColor: '#d33', - confirmButtonText: 'Yes, create link' - }).then((result) => { - - this.showingSwal = false; - - if (result.value) { - - axios.patch(`/file-service/make-one/${this.props.shareSelected._id}`, undefined).then((results) => { - - this.props.dispatch(editFile(this.props.shareSelected._id,{"metadata": { - ...this.props.shareSelected.metadata, - link: results.data, - linkType: "one" - }})) - - this.props.dispatch(editSelectedItem({link: results.data, - linkType: "one"})) - - - this.props.dispatch(editShareSelected({"metadata": { - ...this.props.shareSelected.metadata, - link: results.data, - linkType: "one" - }})) - - }).catch((err) => { - console.log(err) - }) - - - } - }) - - } - - removeLink = () => { - - const url = this.props.shareSelected.metadata.drive ? `/file-service-google/remove-link/${this.props.shareSelected._id}` : `/file-service/remove-link/${this.props.shareSelected._id}` - - axios.delete(url, { - }).then(() => { - - this.props.dispatch(editFile(this.props.shareSelected._id,{"metadata": { - ...this.props.shareSelected.metadata, - link: undefined, - linkType: undefined - }})) - - this.props.dispatch(editSelectedItem({link: undefined, - linkType: undefined})) - - - this.props.dispatch(editShareSelected({"metadata": { - ...this.props.shareSelected.metadata, - link: undefined, - linkType: undefined - }})) - }).catch((err) => { - console.log(err) - }) - } - - copyLink = () => { - - const shareURL = this.props.shareSelected.metadata.drive ? this.state.title : `${currentURL}/download-page/${this.props.shareSelected._id}/${this.props.shareSelected.metadata.link}` - - copy(shareURL) - - Swal.fire("Link Copied") - } - - render() { - - return - } -} - -const connectStateToProps = (state) => ({ - - shareSelected: state.selectedItem.shareSelected -}) - -export default connect(connectStateToProps)(ShareMenuContainer); diff --git a/src/components/ShareModel/index.jsx b/src/components/ShareModel/index.jsx deleted file mode 100644 index 4596960..0000000 --- a/src/components/ShareModel/index.jsx +++ /dev/null @@ -1,594 +0,0 @@ -import React from "react"; -import { connect } from "react-redux"; -import { editFile } from "../../actions/files"; -import axios from "../../axiosInterceptor"; -import env from "../../enviroment/envFrontEnd"; -import capitalize from "../../utils/capitalize"; -import bytes from "bytes"; -import copy from "copy-text-to-clipboard"; -import { - setShareSelected, - editSelectedItem, - editShareSelected, -} from "../../actions/selectedItem"; -import SpinnerImage from "../SpinnerImage"; -import SpinnerPage from "../SpinnerPage"; -import Swal from "sweetalert2"; - -const currentURL = env.url; - -class ShareModelContainer extends React.Component { - constructor(props) { - super(props); - - this.state = { - shareableLink: "Fetching Link...", - loaded: false, - sendTo: "", - emailSent: false, - copySelected: false, - public: false, - shared: false, - }; - - this.lastLoadedID = ""; - } - - componentDidMount = () => { - const id = this.props.shareSelected._id; - - //`/file-service/info/${id}` - - const url = this.props.shareSelected.metadata.drive - ? `/file-service-google/info/${id}` - : `/file-service/info/${id}`; - - axios - .get(url) - .then((response) => { - console.log("file info response", response.data); - - const linkType = response.data.metadata.linkType; - - const shareURL = this.props.shareSelected.metadata.drive - ? response.data.metadata.link - : `${currentURL}/download-page/${this.props.shareSelected._id}/${this.props.shareSelected.metadata.link}`; - - console.log("share link type", linkType, response.data); - - this.setState(() => ({ - ...this.state, - shared: linkType ? true : false, - loaded: true, - shareableLink: shareURL, - })); - }) - .catch((e) => { - console.log("Cannot get share file data", e); - }); - }; - - componentDidUpdate = () => { - // console.log("share model updated"); - // if (this.lastLoadedID !== this.props.shareSelected._id && this.props.shareSelected !== "") { - // if (this.props.shareSelected.metadata.link && !this.props.shareSelected.metadata.drive) { - // console.log("link already exists"); - // this.lastLoadedID = this.props.shareSelected._id; - // const shareURL = this.props.shareSelected.metadata.drive ? results.data : `${currentURL}/download-page/${this.props.shareSelected._id}/${this.props.shareSelected.metadata.link}` - // return this.setState(() => { - // return { - // ...this.state, - // shareableLink: shareURL, - // loaded: true, - // public: true - // } - // }) - // } - // this.lastLoadedID = this.props.shareSelected._id; - // console.log("share props", this.props.shareSelected) - // const url = this.props.shareSelected.metadata.drive ? currentURL +`/file-service-google/make-public/${this.props.shareSelected._id}` : currentURL +`/file-service/make-public/${this.props.shareSelected._id}`; - // console.log("share", url) - // axios.patch(url, undefined).then((results) => { - // this.props.shareSelected.metadata.link = results.data; - // this.props.dispatch(editFile(this.props.shareSelected._id,{"metadata": { - // ...this.props.shareSelected.metadata, - // link: results.data, - // linkType: "public" - // }})); - // const shareURL = this.props.shareSelected.metadata.drive ? results.data : `${currentURL}/download-page/${this.props.shareSelected._id}/${this.props.shareSelected.metadata.link}` - // this.setState(() => { - // return { - // ...this.state, - // shareableLink: shareURL, - // loaded: true, - // public: true - // } - // }) - // }) - // } - }; - - sendEmail = (e) => { - e.preventDefault(); - - if (this.state.sendTo.length === 0 || !this.state.loaded) return; - - if (!this.state.shared) { - Swal.fire({ - icon: "error", - title: "You must share the file first", - text: "Select make public or make one time before sending email", - }); - return; - } - - console.log("sending email share request"); - - const data = { - file: { - _id: this.props.shareSelected._id, - resp: this.state.sendTo, - }, - }; - - axios - .post("/file-service/send-share-email", data) - .then((response) => { - console.log("sent email share"); - - this.setState(() => { - return { - ...this.state, - emailSent: true, - }; - }); - }) - .catch((err) => { - console.log("share file email failed", err); - Swal.fire({ - icon: "error", - title: "Cannot send share email", - text: "An error occurred when sending share email", - }); - }); - }; - - onChangeEmail = (e) => { - const value = e.target.value; - - this.setState(() => { - return { - ...this.state, - sendTo: value, - }; - }); - }; - - closeShareModel = () => { - this.props.dispatch(setShareSelected("")); - this.setState(() => { - return { - shareableLink: "Fetching Link...", - loaded: false, - sendTo: "", - emailSent: false, - copySelected: false, - public: false, - }; - }); - this.lastLoadedID = ""; - }; - - copyClick = () => { - if (!this.state.loaded) return; - - copy(this.state.shareableLink); - - console.log("link copied"); - - this.setState( - () => { - return { - ...this.state, - copySelected: true, - }; - }, - () => { - console.log("new state set"); - - window.setTimeout(() => { - this.setState(() => { - return { - ...this.state, - copySelected: false, - }; - }); - }, 750); - } - ); - }; - - removePublicLink = async () => { - const url = this.props.shareSelected.metadata.drive - ? `/file-service-google/remove-link/${this.props.shareSelected._id}` - : `/file-service/remove-link/${this.props.shareSelected._id}`; - - axios - .delete(url, {}) - .then(() => { - this.props.dispatch( - editFile(this.props.shareSelected._id, { - metadata: { - ...this.props.shareSelected.metadata, - link: undefined, - linkType: undefined, - }, - }) - ); - - this.props.dispatch( - editSelectedItem({ link: undefined, linkType: undefined }) - ); - - this.props.dispatch( - editShareSelected({ - metadata: { - ...this.props.shareSelected.metadata, - link: undefined, - linkType: undefined, - }, - }) - ); - - this.setState(() => ({ - ...this.state, - shared: false, - })); - - //this.closeShareModel(); - }) - .catch((err) => { - console.log(err); - Swal.fire({ - icon: "error", - title: "Cannot remove public link", - text: "An error occurred when removing public link", - }); - }); - }; - - makePublic = () => { - this.showingSwal = true; - - Swal.fire({ - title: "Are you sure?", - text: "Making this public, will allow anyone to have access to it", - icon: "warning", - showCancelButton: true, - confirmButtonColor: "#3085d6", - cancelButtonColor: "#d33", - confirmButtonText: "Yes, make public", - }).then((result) => { - this.showingSwal = false; - - if (result.value) { - const url = this.props.shareSelected.metadata.drive - ? `/file-service-google/make-public/${this.props.shareSelected._id}` - : `/file-service/make-public/${this.props.shareSelected._id}`; - - axios - .patch(url, undefined) - .then((results) => { - this.props.dispatch( - editFile(this.props.shareSelected._id, { - metadata: { - ...this.props.shareSelected.metadata, - link: results.data, - linkType: "public", - }, - }) - ); - - this.props.dispatch( - editSelectedItem({ link: results.data, linkType: "public" }) - ); - - this.props.dispatch( - editShareSelected({ - metadata: { - ...this.props.shareSelected.metadata, - link: results.data, - linkType: "public", - }, - }) - ); - - const shareURL = this.props.shareSelected.metadata.drive - ? results.data - : `${currentURL}/download-page/${this.props.shareSelected._id}/${results.data}`; - - this.setState(() => ({ - ...this.state, - shared: true, - shareableLink: shareURL, - })); - }) - .catch((err) => { - console.log(err); - Swal.fire({ - icon: "error", - title: "Cannot make public", - text: "An error occurred when making file public", - }); - }); - } - }); - }; - - makeOne = () => { - this.showingSwal = true; - - Swal.fire({ - title: "Are you sure?", - text: "One time link, will allow anyone to access this file once", - icon: "warning", - showCancelButton: true, - confirmButtonColor: "#3085d6", - cancelButtonColor: "#d33", - confirmButtonText: "Yes, create link", - }).then((result) => { - this.showingSwal = false; - - if (result.value) { - axios - .patch( - `/file-service/make-one/${this.props.shareSelected._id}`, - undefined - ) - .then((results) => { - this.props.dispatch( - editFile(this.props.shareSelected._id, { - metadata: { - ...this.props.shareSelected.metadata, - link: results.data, - linkType: "one", - }, - }) - ); - - this.props.dispatch( - editSelectedItem({ link: results.data, linkType: "one" }) - ); - - this.props.dispatch( - editShareSelected({ - metadata: { - ...this.props.shareSelected.metadata, - link: results.data, - linkType: "one", - }, - }) - ); - - this.setState(() => ({ - ...this.state, - shared: true, - })); - - const shareURL = this.props.shareSelected.metadata.drive - ? results.data - : `${currentURL}/download-page/${this.props.shareSelected._id}/${results.data}`; - - this.setState(() => ({ - ...this.state, - shared: true, - shareableLink: shareURL, - })); - }) - .catch((err) => { - console.log(err); - Swal.fire({ - icon: "error", - title: "Cannot make one time public link", - text: "An error occurred when making one time public link", - }); - }); - } - }); - }; - - removeLink = () => { - const url = this.props.shareSelected.metadata.drive - ? `/file-service-google/remove-link/${this.props.shareSelected._id}` - : `/file-service/remove-link/${this.props.shareSelected._id}`; - - axios - .delete(url, {}) - .then(() => { - this.props.dispatch( - editFile(this.props.shareSelected._id, { - metadata: { - ...this.props.shareSelected.metadata, - link: undefined, - linkType: undefined, - }, - }) - ); - - this.props.dispatch( - editSelectedItem({ link: undefined, linkType: undefined }) - ); - - this.props.dispatch( - editShareSelected({ - metadata: { - ...this.props.shareSelected.metadata, - link: undefined, - linkType: undefined, - }, - }) - ); - }) - .catch((err) => { - console.log(err); - Swal.fire({ - icon: "error", - title: "Cannot remove public link", - text: "An error occurred when removing public link", - }); - }); - }; - - render() { - return ( -
-
-
-
-
- extension -
-
-

- {this.props.shareSelected !== "" - ? capitalize(this.props.shareSelected.filename) - : ""} -

- - {this.props.shareSelected !== "" - ? bytes(this.props.shareSelected.length) - : 0} - -
-
- - close - -
-
-
-

Send to:

-
-
- - {/* Email address */} -
-
- -
-
-
-

- - success - {" "} - Email sent successfully -

-
-
-
- -
-
-
- -
-
- -
-
-
-

File link:

-
-
-

- check Copied -

-
- - - copy - -
-
-
- -
-
-
-
- ); - } -} - -const connectStoreToProp = (state) => ({ - shareSelected: state.selectedItem.shareSelected, -}); - -export default connect(connectStoreToProp)(ShareModelContainer); diff --git a/src/components/ShareModelWrapper/index.jsx b/src/components/ShareModelWrapper/index.jsx deleted file mode 100644 index 04c481f..0000000 --- a/src/components/ShareModelWrapper/index.jsx +++ /dev/null @@ -1,24 +0,0 @@ -import React from "react"; -import {connect} from "react-redux"; -import ShareModel from "../ShareModel"; - -class ShareModelWrapper extends React.Component { - - constructor(props) { - super(props); - } - - render() { - return ( -
- {this.props.shareSelected !== "" ? : undefined} -
- ) - } -} - -const connectPropToStore = (state) => ({ - shareSelected: state.selectedItem.shareSelected -}) - -export default connect(connectPropToStore)(ShareModelWrapper) \ No newline at end of file diff --git a/src/components/UploadOverlay/UploadOverlay.jsx b/src/components/UploadOverlay/UploadOverlay.jsx deleted file mode 100644 index 9933657..0000000 --- a/src/components/UploadOverlay/UploadOverlay.jsx +++ /dev/null @@ -1,23 +0,0 @@ -import React from "react"; - -const UploadOverlay = (props) => ( -
-
-
- upload -
-

Drop your files anywhere to start uploading

-
-
-); - -export default UploadOverlay; diff --git a/src/components/UploadOverlay/index.jsx b/src/components/UploadOverlay/index.jsx deleted file mode 100644 index 94829d9..0000000 --- a/src/components/UploadOverlay/index.jsx +++ /dev/null @@ -1,61 +0,0 @@ -import React from "react"; -import {connect} from "react-redux" -import { startAddFile } from "../../actions/files"; -import { closeUploadOverlay } from "../../actions/main"; -import UploadOverlay from "./UploadOverlay"; - -class UploadOverlayContainer extends React.Component { - - constructor(props) { - super(props) - } - - onDragDropEvent = (e) => { - - e.preventDefault() - - const fileInput = e.dataTransfer; - - this.props.dispatch(startAddFile(fileInput, this.props.parent, this.props.parentList, this.props.storageSwitcher)) - this.closeOverlay() - } - - onDragEnterEvent = (e) => { - e.preventDefault() - } - - onDragLeaveEvent = (e) => { - e.preventDefault() - } - - onDragOverEvent = (e) => { - e.preventDefault() - } - - closeOverlay = () => { - - this.props.dispatch(closeUploadOverlay()); - } - - render() { - return ( - - - ) - } -} - -const connectStoreToProp = (state) => ({ - uploadOverlayOpen: state.main.uploadOverlayOpen, - parent: state.parent.parent, - parentList: state.parent.parentList, - storageSwitcher: state.storageSwitcher.selected -}) - -export default connect(connectStoreToProp)(UploadOverlayContainer); \ No newline at end of file diff --git a/src/store/configureStore.ts b/src/store/configureStore.ts index 55b5145..7c04b75 100755 --- a/src/store/configureStore.ts +++ b/src/store/configureStore.ts @@ -27,25 +27,25 @@ const store = configureStore({ reducer: { auth: authReducer, main: mainReducer, - files: fileReducer, - folders: folderReducer, + // files: fileReducer, + // folders: folderReducer, filter: filterReducer, selected: selectedReducer, leftSection: leftSectionReducer, - selectedItem: selectedItemReducer, + // selectedItem: selectedItemReducer, uploads: uploadsReducer, - storage: storageReducer, - quickFiles: quickFilesReducer, - popupFile: popupFilesReducer, - settings: settingsReducer, - parent: parentReducer, - addOptions: addOptionsReducer, - photoViewer: photoViewerReducer, - routes: routesReducer, - mover: moverReducer, - folderTree: folderTreeReducer, - storageSwitcher: uploadStorageSwitcherReducer, - mobileContextMenu: mobileContextMenuReducer, + // storage: storageReducer, + // quickFiles: quickFilesReducer, + // popupFile: popupFilesReducer, + // settings: settingsReducer, + // parent: parentReducer, + // addOptions: addOptionsReducer, + // photoViewer: photoViewerReducer, + // routes: routesReducer, + // mover: moverReducer, + // folderTree: folderTreeReducer, + // storageSwitcher: uploadStorageSwitcherReducer, + // mobileContextMenu: mobileContextMenuReducer, }, });