Skip to content
Snippets Groups Projects
App.tsx 2.08 KiB
Newer Older
  • Learn to ignore specific revisions
  • Jorik Schellekens's avatar
    Jorik Schellekens committed
    /*
    Copyright 2020 The Matrix.org Foundation C.I.C.
    
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    
        http://www.apache.org/licenses/LICENSE-2.0
    
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
    */
    
    
    import React, { useState, useEffect } from 'react';
    
    Jorik Schellekens's avatar
    Jorik Schellekens committed
    
    
    import SingleColumn from './layouts/SingleColumn';
    import CreateLinkTile from './components/CreateLinkTile';
    import MatrixTile from './components/MatrixTile';
    import Tile from './components/Tile';
    import LinkRouter from './pages/LinkRouter';
    
    import GlobalContext from './contexts/GlobalContext';
    
    
    /* eslint-disable no-restricted-globals */
    
    Jorik Schellekens's avatar
    Jorik Schellekens committed
    
    
    Jorik Schellekens's avatar
    Jorik Schellekens committed
    const App: React.FC = () => {
    
        const [hash, setHash] = useState(location.hash);
    
    
        console.log(`Link for ${hash}`);
    
    
        useEffect(() => {
            // Some hacky uri decoding
            if (location.href.split('/').length > 4) {
                location.href = decodeURIComponent(location.href);
            }
    
            window.onhashchange = () => setHash(location.hash);
        }, []);
    
    
        if (hash) {
            if (hash.startsWith('#/')) {
                page = <LinkRouter link={hash.slice(2)} />;
    
                        Links should be in the format {location.host}/#/{'<'}
                        matrix-resource-identifier{'>'}
    
    Jorik Schellekens's avatar
    Jorik Schellekens committed
        return (
    
            <GlobalContext>
                <SingleColumn>
                    <div className="topSpacer" />
                    {page}
    
                    <MatrixTile isLink={!!location.hash} />
    
                    <div className="bottomSpacer" />
                </SingleColumn>
            </GlobalContext>
    
    Jorik Schellekens's avatar
    Jorik Schellekens committed
        );
    
    Jorik Schellekens's avatar
    Jorik Schellekens committed
    };
    
    Jorik Schellekens's avatar
    Jorik Schellekens committed
    
    export default App;