added ability to delete items from image menu, looked into reworking ipfs
minor css changes too
This commit is contained in:
parent
7be6148337
commit
0763b8b455
3 changed files with 36 additions and 10 deletions
|
@ -61,7 +61,7 @@ export class ImageAdder extends React.Component< ImageAddedProps, ImageAdderStat
|
||||||
}
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
private async onFileLoad( file: File, result: ArrayBuffer ) //we add the binaries to the ipfs node then convert it into a blob we can display, when accessing this from a remote gadget you'll need to create a blob since we havent uploaded this as one
|
private async onFileLoad( file: File, result: ArrayBuffer )
|
||||||
{
|
{
|
||||||
let res = await this.ipfsNode.add( new Uint8Array( result ) );
|
let res = await this.ipfsNode.add( new Uint8Array( result ) );
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ export class ImageAdder extends React.Component< ImageAddedProps, ImageAdderStat
|
||||||
const blobData: ArrayBuffer[] = [result];
|
const blobData: ArrayBuffer[] = [result];
|
||||||
const imageBlob = new Blob(blobData);
|
const imageBlob = new Blob(blobData);
|
||||||
this.props.addImageCallback( URL.createObjectURL(imageBlob) );
|
this.props.addImageCallback( URL.createObjectURL(imageBlob) );
|
||||||
|
//this.props.addImageCallback("https://ipfs.io/ipfs/" + res.cid) <- this system is more efficient but slower as it relies on waiting for a return from the ipfs server and that server gets alot of requests
|
||||||
}
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
|
|
17
src/main.tsx
17
src/main.tsx
|
@ -6,7 +6,7 @@ import * as ReactDOM from 'react-dom';
|
||||||
import { ImageAdder } from './imageadder';
|
import { ImageAdder } from './imageadder';
|
||||||
import * as IPFS from 'ipfs';
|
import * as IPFS from 'ipfs';
|
||||||
|
|
||||||
class MenuItem extends React.Component< {displayImage, onClick}, {}> //class for items on the menu, basically just a button
|
class MenuItem extends React.Component< {displayImage, onClick, deleteSelfCallback}, {}> //class for items on the menu, basically just a button
|
||||||
{
|
{
|
||||||
constructor(props)
|
constructor(props)
|
||||||
{
|
{
|
||||||
|
@ -16,9 +16,12 @@ class MenuItem extends React.Component< {displayImage, onClick}, {}> //class for
|
||||||
public render()
|
public render()
|
||||||
{
|
{
|
||||||
return(
|
return(
|
||||||
|
<div className = "imageMenuButtonContainer">
|
||||||
<button className = "imageMenuButton" onClick = {this.props.onClick}>
|
<button className = "imageMenuButton" onClick = {this.props.onClick}>
|
||||||
<img src = {this.props.displayImage} className = "imageMenuImage"/>
|
<img src = {this.props.displayImage} className = "imageMenuImage"/>
|
||||||
</button>
|
</button>
|
||||||
|
<button className = "imageMenuDeleteButton" onClick = {this.props.deleteSelfCallback}>X</button>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,12 +76,18 @@ class ImageMenu extends React.Component< {}, ImageMenuState> //class for the who
|
||||||
this.forceUpdate();
|
this.forceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public deleteListItem(item: string)
|
||||||
|
{
|
||||||
|
this.state.imageUrls.splice(this.state.imageUrls.indexOf(item), 1);
|
||||||
|
this.forceUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
public render()
|
public render()
|
||||||
{
|
{
|
||||||
if (this.imageToDisplay){ //if theres an image then show that, and also a back button
|
if (this.imageToDisplay){ //if theres an image then show that, and also a back button
|
||||||
return(
|
return(
|
||||||
<div>
|
<div>
|
||||||
<button className = "imageDisplayButton" onClick = {() => this.removeImage()}>ᐊ</button>
|
<button className = "imageDisplayBackButton" onClick = {() => this.removeImage()}>ᐊ</button>
|
||||||
<div style = {{textAlign: "center"}}>
|
<div style = {{textAlign: "center"}}>
|
||||||
<img className = "displayedImage" src = {this.imageToDisplay}/>
|
<img className = "displayedImage" src = {this.imageToDisplay}/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -95,7 +104,7 @@ class ImageMenu extends React.Component< {}, ImageMenuState> //class for the who
|
||||||
};
|
};
|
||||||
return(
|
return(
|
||||||
<div style = {itemStyle}>
|
<div style = {itemStyle}>
|
||||||
<MenuItem displayImage = {image} onClick = {() => this.displayImage(image)}/>
|
<MenuItem displayImage = {image} onClick = {() => this.displayImage(image)} deleteSelfCallback = {() => this.deleteListItem(image)}/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -183,7 +192,7 @@ renderAardvarkRoot( "root", <MyGadget/> );
|
||||||
//DONT FORGET TO RUN NPM START AAAAAAAAAAAAAAAAAAAA YOU ALWAYS FORGETTT
|
//DONT FORGET TO RUN NPM START AAAAAAAAAAAAAAAAAAAA YOU ALWAYS FORGETTT
|
||||||
/*
|
/*
|
||||||
todo:
|
todo:
|
||||||
look into using ipfs for images
|
add ability for remote users?
|
||||||
look into using avmodel to create pop-up images
|
look into using avmodel to create pop-up images
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,10 @@ body, html
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
button{
|
button{
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
border: 3px solid black;
|
border: border: 1px solid black;
|
||||||
}
|
}
|
||||||
|
|
||||||
.Button
|
.Button
|
||||||
|
@ -59,6 +60,7 @@ button{
|
||||||
|
|
||||||
.imageMenuDeleteButton{
|
.imageMenuDeleteButton{
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
.imageMenuImage{
|
.imageMenuImage{
|
||||||
|
@ -82,18 +84,32 @@ button{
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.imageDisplayButton{
|
.imageDisplayBackButton{
|
||||||
font-size: 3rem;
|
font-size: 3rem;
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.imageDisplayBackButton:hover{
|
||||||
|
background-color: rgba(128, 128, 128, 0.234);
|
||||||
|
}
|
||||||
|
|
||||||
|
.imageMenuDeleteButton:hover{
|
||||||
|
background-color: rgba(128, 128, 128, 0.234);
|
||||||
}
|
}
|
||||||
|
|
||||||
#noImageText{
|
#noImageText{
|
||||||
font-size: 3rem;
|
font-size: 3rem;
|
||||||
color: grey;
|
background-color: transparent;
|
||||||
background-color: white;
|
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
border: 1px solid black
|
||||||
}
|
}
|
||||||
|
|
||||||
#uploadButton{
|
#uploadButton{
|
||||||
font-size: 3rem;
|
font-size: 3rem;
|
||||||
margin-top: 5vh;
|
margin-top: 5vh;
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
#uploadButton:hover{
|
||||||
|
background-color: rgba(128, 128, 128, 0.234);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue