Set active Fling from URL match
Instead of a mix between URL matching and manually setting the active fling, set the active fling from the URL. This fixes some strange edge cases where current URL and selected fling do not add up.
This commit is contained in:
parent
857535bb93
commit
b8471deecc
6 changed files with 20 additions and 22 deletions
|
@ -12,7 +12,8 @@ export default () => {
|
||||||
return (
|
return (
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route exact path="/admin/login" component={Login} />
|
<Route exact path="/admin/login" component={Login} />
|
||||||
<OwnerRoute path="/admin"><Fling /></OwnerRoute>
|
<OwnerRoute exact path="/admin"><Fling /></OwnerRoute>
|
||||||
|
<OwnerRoute path="/admin/:fling"><Fling /></OwnerRoute>
|
||||||
<Route match="*">Not implemented</Route>
|
<Route match="*">Not implemented</Route>
|
||||||
</Switch>
|
</Switch>
|
||||||
);
|
);
|
||||||
|
|
|
@ -5,21 +5,19 @@ import Navbar from './Navbar';
|
||||||
import FlingList from './FlingList';
|
import FlingList from './FlingList';
|
||||||
import FlingContent from './FlingContent';
|
import FlingContent from './FlingContent';
|
||||||
|
|
||||||
import {BrowserRouter} from 'react-router-dom';
|
import {useParams, BrowserRouter} from 'react-router-dom';
|
||||||
|
|
||||||
export default function Fling() {
|
export default function Fling() {
|
||||||
const [activeFling, setActiveFling] = useState(undefined);
|
let { fling } = useParams();
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<div>
|
<div>
|
||||||
<Navbar />
|
<Navbar />
|
||||||
<div className="container">
|
<div className="container">
|
||||||
<div className="columns mt-2">
|
<div className="columns mt-2">
|
||||||
<div className="column col-sm-12 col-lg-3 col-2"> <FlingList setActiveFlingFn={setActiveFling} activeFling={activeFling} /> </div>
|
<div className="column col-sm-12 col-lg-3 col-2"> <FlingList activeFling={fling} /> </div>
|
||||||
<div className="column col-sm-12">
|
<div className="column col-sm-12">
|
||||||
<BrowserRouter>
|
<FlingContent activeFling={fling} />
|
||||||
<FlingContent activeFling={activeFling} />
|
|
||||||
</BrowserRouter>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -12,7 +12,6 @@ import Settings from './Settings';
|
||||||
|
|
||||||
export default function FlingContent(props) {
|
export default function FlingContent(props) {
|
||||||
let location = useLocation();
|
let location = useLocation();
|
||||||
let { fling } = useParams();
|
|
||||||
|
|
||||||
function path(tail) {
|
function path(tail) {
|
||||||
return `/admin/${props.activeFling}/${tail}`;
|
return `/admin/${props.activeFling}/${tail}`;
|
||||||
|
@ -20,6 +19,8 @@ export default function FlingContent(props) {
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<div className="fling-content p-2">
|
<div className="fling-content p-2">
|
||||||
|
{log.info("FlingContent location ", location)}
|
||||||
|
{log.info("FlingContent active fling ", props.activeFling)}
|
||||||
<ul className="tab tab-block mt-0">
|
<ul className="tab tab-block mt-0">
|
||||||
<li className={`tab-item ${location.pathname !== path("upload") && location.pathname !== path("settings") ? "active": ""}`}>
|
<li className={`tab-item ${location.pathname !== path("upload") && location.pathname !== path("settings") ? "active": ""}`}>
|
||||||
<Link to={path("files")}>Files</Link>
|
<Link to={path("files")}>Files</Link>
|
||||||
|
@ -34,9 +35,10 @@ export default function FlingContent(props) {
|
||||||
|
|
||||||
<div className="mt-2">
|
<div className="mt-2">
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route exact path={["/admin/:fling/files","/admin"]}><FlingArtifacts activeFling={props.activeFling} /></Route>
|
<Route exact path="/admin/:fling"><FlingArtifacts activeFling={props.activeFling} /></Route>
|
||||||
|
<Route path="/admin/:fling/files"><FlingArtifacts activeFling={props.activeFling} /></Route>
|
||||||
<Route path="/admin/:fling/upload"><Upload activeFling={props.activeFling} /></Route>
|
<Route path="/admin/:fling/upload"><Upload activeFling={props.activeFling} /></Route>
|
||||||
<Route path="/admin/:fling/settings"><Settings activeFling={props.activeFling}/></Route>
|
<Route path="/admin/:fling/settings"><Settings activeFling={props.activeFling} /></Route>
|
||||||
</Switch>
|
</Switch>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -7,10 +7,11 @@ import FlingTile from './FlingTile';
|
||||||
|
|
||||||
export default function FlingList(props) {
|
export default function FlingList(props) {
|
||||||
const [flings, setFlings] = useState([]);
|
const [flings, setFlings] = useState([]);
|
||||||
useEffect(() => { refreshFlingList(); }, [props.activeFling]);
|
useEffect(() => { refreshFlingList(); }, []);
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<div className="panel">
|
<div className="panel">
|
||||||
|
{log.info(`Got active fling: ${props.activeFling}`)}
|
||||||
<div className="panel-header p-2">
|
<div className="panel-header p-2">
|
||||||
<h5>My Flings</h5>
|
<h5>My Flings</h5>
|
||||||
</div>
|
</div>
|
||||||
|
@ -27,8 +28,6 @@ export default function FlingList(props) {
|
||||||
for (let fling of flings) {
|
for (let fling of flings) {
|
||||||
let flingTile = <FlingTile fling={fling}
|
let flingTile = <FlingTile fling={fling}
|
||||||
key={fling.id}
|
key={fling.id}
|
||||||
activeFling={props.activeFling}
|
|
||||||
setActiveFlingFn={props.setActiveFlingFn}
|
|
||||||
refreshFlingListFn={refreshFlingList} />;
|
refreshFlingListFn={refreshFlingList} />;
|
||||||
newFlings.push(flingTile);
|
newFlings.push(flingTile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import log from 'loglevel';
|
import log from 'loglevel';
|
||||||
import React, {useRef, useState} from 'react';
|
import React, {useRef, useState} from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
import {Switch, Route, Redirect, BrowserRouter, useLocation, useParams, NavLink} from "react-router-dom";
|
||||||
|
|
||||||
import {flingClient} from '../../util/flingclient';
|
import {flingClient} from '../../util/flingclient';
|
||||||
|
|
||||||
|
@ -70,17 +71,14 @@ export default function FlingTile(props) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className={tileClasses}>
|
<div className={tileClasses}>
|
||||||
<div className="tile-content" onClick={() => activateTile(props.fling.id)}>
|
<div className="tile-content">
|
||||||
<div className="tile-title">{props.fling.name}</div>
|
<NavLink to={`/admin/${props.fling.id}`}>
|
||||||
<small className="tile-subtitle text-gray">14MB · Public · 1 Jan, 2017</small>
|
<div className="tile-title">{props.fling.name}</div>
|
||||||
|
<small className="tile-subtitle text-gray">14MB · Public · 1 Jan, 2017</small>
|
||||||
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
<TileAction fling={props.fling} refreshFlingListFn={props.refreshFlingListFn} />
|
<TileAction fling={props.fling} refreshFlingListFn={props.refreshFlingListFn} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
function activateTile() {
|
|
||||||
log.debug(`Activating fling ${props.fling.id}`);
|
|
||||||
props.setActiveFlingFn(props.fling.id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ export default function Navbar() {
|
||||||
return (
|
return (
|
||||||
<header className="navbar">
|
<header className="navbar">
|
||||||
<section className="navbar-section">
|
<section className="navbar-section">
|
||||||
<a href="/" className="navbar-brand">
|
<a href="/admin" className="navbar-brand">
|
||||||
<img src={send} alt="Fling logo"/>
|
<img src={send} alt="Fling logo"/>
|
||||||
Fling
|
Fling
|
||||||
</a>
|
</a>
|
||||||
|
|
Loading…
Reference in a new issue