garage-box/src/BucketList.tsx

43 lines
867 B
TypeScript
Raw Normal View History

2022-02-28 11:30:54 +00:00
import React from 'react';
2022-02-28 16:08:49 +00:00
import { Link } from 'react-router-dom';
2022-02-28 11:30:54 +00:00
import { S3Client, ListBucketsCommand } from '@aws-sdk/client-s3';
type Props = {
client: S3Client;
};
type State = {
buckets: string[];
};
class BucketList extends React.Component<Props, State> {
state = {
buckets: [],
};
2022-02-28 16:08:49 +00:00
async componentDidMount() {
2022-02-28 11:30:54 +00:00
let command = new ListBucketsCommand({});
try {
const data = await this.props.client.send(command);
console.log("ok", data);
const buckets = (data.Buckets || []).map((b) => (b.Name || 'aza'));
this.setState({buckets: buckets});
} catch(error) {
console.log("err", error);
}
}
render() {
return (
<ul>
{ this.state.buckets.map((b) =>
2022-02-28 16:08:49 +00:00
<li key={ b }><Link to={ "/" + b }>{ b }</Link></li>
2022-02-28 11:30:54 +00:00
)}
</ul>
);
}
}
export default BucketList;