From 8d937ca10eaafb4c5e6397166637216f67c99d28 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 28 Feb 2022 17:15:39 +0100 Subject: [PATCH] Add parent --- src/ObjectList.tsx | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/ObjectList.tsx b/src/ObjectList.tsx index 7dcb264..f981c05 100644 --- a/src/ObjectList.tsx +++ b/src/ObjectList.tsx @@ -9,12 +9,14 @@ type Props = { }; type State = { + loaded: boolean; folders: string[]; files: string[]; }; class ObjectList extends React.Component { state = { + loaded: false, folders: [], files: [], }; @@ -32,23 +34,52 @@ class ObjectList extends React.Component { Delimiter: '/', }); try { + const pxlen = this.props.prefix.length; + const data = await this.props.client.send(command); console.log("ok", data); this.setState({ - folders: (data.CommonPrefixes || []).map((cp) => cp.Prefix!), - files: (data.Contents || []).map((obj) => obj.Key!), + loaded: true, + folders: (data.CommonPrefixes || []).map((cp) => cp.Prefix!.substring(pxlen)), + files: (data.Contents || []).map((obj) => obj.Key!.substring(pxlen)), }); } catch(error) { console.log("err", error); } } + parentTag() { + let spl = this.props.prefix.split("/"); + while (spl.pop() == ""); + spl.push(""); + let pp = spl.join("/"); + return ( +
  • + .. +
  • + ); + } + render() { + let par = (this.props.prefix.length > 0 ? + this.parentTag() + : <>); + + if (!this.state.loaded) { + return ( +
      + { par } +
    • Loading...
    • +
    + ); + } + return (
      + { par } { this.state.folders.map((f) =>
    • - { f } + { f }
    • )} { this.state.files.map((f) =>