mirror of
				https://github.com/mickael-kerjean/filestash.git
				synced 2025-11-04 13:35:46 +08:00 
			
		
		
		
	maintenance (homepage): migrate homepage to recent react
This commit is contained in:
		@ -1,36 +1,24 @@
 | 
				
			|||||||
import React from 'react';
 | 
					import React, { useState, useEffect } from 'react';
 | 
				
			||||||
import { Redirect } from 'react-router';
 | 
					import { Redirect } from "react-router";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { Session } from '../model/';
 | 
					import { Session } from "../model/";
 | 
				
			||||||
import { Loader } from '../components/';
 | 
					import { Loader } from "../components/";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export class HomePage extends React.Component {
 | 
					export function HomePage() {
 | 
				
			||||||
    constructor(props){
 | 
					    const [redirection, setRedirection] = useState(null);
 | 
				
			||||||
        super(props);
 | 
					 | 
				
			||||||
        this.state = {
 | 
					 | 
				
			||||||
            redirection: null
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    componentDidMount(){
 | 
					    useEffect(() => {
 | 
				
			||||||
        Session.currentUser()
 | 
					        Session.currentUser().then((res) => {
 | 
				
			||||||
            .then((res) => {
 | 
					            if(res && res.is_authenticated === true){
 | 
				
			||||||
                if(res && res.is_authenticated === true){
 | 
					                setRedirection(res.home ? "/files" + res.home : "/files");
 | 
				
			||||||
                    let url = "/files"
 | 
					            }else{
 | 
				
			||||||
                    if(res.home){
 | 
					                setRedirection("/login");
 | 
				
			||||||
                        url += res.home
 | 
					            }
 | 
				
			||||||
                    }
 | 
					        }).catch((err) => setRedirection("/login"));
 | 
				
			||||||
                    this.setState({redirection: url});
 | 
					    }, []);
 | 
				
			||||||
                }else{
 | 
					
 | 
				
			||||||
                    this.setState({redirection: "/login"});
 | 
					    if(!redirection) {
 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            })
 | 
					 | 
				
			||||||
            .catch((err) => this.setState({redirection: "/login"}));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    render() {
 | 
					 | 
				
			||||||
        if(this.state.redirection !== null){
 | 
					 | 
				
			||||||
            return ( <Redirect to={this.state.redirection} /> );
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return ( <div> <Loader /> </div> );
 | 
					        return ( <div> <Loader /> </div> );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    return ( <Redirect to={redirection} /> );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user