Merge branch 'base64' into 'dev'

Resolve "convert img to base64"

Closes #49

See merge request sa4-2020/the-sanmarinoes/frontend!59
This commit is contained in:
Claudio Maggioni 2020-03-24 16:06:17 +01:00
commit 105bb4e088
7 changed files with 68 additions and 60 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View file

@ -5,14 +5,11 @@ import {
BrowserView, BrowserView,
MobileView, MobileView,
isBrowser, isBrowser,
isMobile isMobile,
} from "react-device-detect"; } from "react-device-detect";
const AvatarImage = () => ( const AvatarImage = () => (
<Image <Image src="avatar3.png" style={{ width: "25px", height: "auto" }} centered />
src="avatar3.png"
style={{ width: "25px", height: "auto" }}
centered />
); );
const IconHomeImage = () => ( const IconHomeImage = () => (
@ -35,13 +32,7 @@ const IconHomeImageMobile = () => (
/> />
); );
const TitleImage = () => ( const TitleImage = () => <Image src="title7.png" size="medium" centered />;
<Image
src="title7.png"
size="medium"
centered
/>
);
const BrowserStructure = (props) => ( const BrowserStructure = (props) => (
<Grid columns="equal" divided inverted padded> <Grid columns="equal" divided inverted padded>
@ -113,13 +104,6 @@ const MobileStructure = (props) => (
</Grid> </Grid>
); );
export default class MyHeader extends React.Component { export default class MyHeader extends React.Component {
render() { render() {
return ( return (

View file

@ -1,5 +1,5 @@
import React, { Component } from "react"; import React, { Component } from "react";
import { Button, Grid } from "semantic-ui-react"; import { Button, Grid, Responsive } from "semantic-ui-react";
export default class SelectIcons extends Component { export default class SelectIcons extends Component {
constructor(props) { constructor(props) {
@ -30,7 +30,7 @@ export default class SelectIcons extends Component {
]; ];
return ( return (
<Grid centered> <Grid centered relaxed>
{myicons.map((e, i) => { {myicons.map((e, i) => {
return ( return (
<Grid.Row key={i}> <Grid.Row key={i}>

View file

@ -7,20 +7,28 @@ import {
Input, Input,
Icon, Icon,
Responsive, Responsive,
Image,
} from "semantic-ui-react"; } from "semantic-ui-react";
import SelectIcons from "./SelectIcons"; import SelectIcons from "./SelectIcons";
const NO_IMAGE = "https://react.semantic-ui.com/images/wireframe/image.png";
export default class ModalWindow extends Component { export default class ModalWindow extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
console.table(this.props);
this.state = { this.state = {
id: "", id: "",
selectedIcon: "", selectedIcon: "",
name: this.props.type === "new" ? "" : this.props.idRoom.name, name: this.props.type === "new" ? "" : this.props.idRoom.name,
img: this.props.type === "new" ? "" : this.props.idRoom.images, img: this.props.type === "new" ? null : this.props.idRoom.image,
openModal: false, openModal: false,
}; };
this.fileInputRef = React.createRef();
this.addRoomModal = this.addRoomModal.bind(this); this.addRoomModal = this.addRoomModal.bind(this);
this.updateIcon = this.updateIcon.bind(this); this.updateIcon = this.updateIcon.bind(this);
} }
@ -72,6 +80,16 @@ export default class ModalWindow extends Component {
this.setState({ selectedIcon: e }); this.setState({ selectedIcon: e });
} }
getBase64(file, callback) {
let reader = new FileReader();
reader.readAsDataURL(file.target.files[0]);
reader.onload = () => {
this.state.img = reader.result;
this.setState(this.state);
};
reader.onerror = console.error;
}
render() { render() {
const spaceDiv = { const spaceDiv = {
background: "#f4f4f4", background: "#f4f4f4",
@ -91,6 +109,16 @@ export default class ModalWindow extends Component {
<Icon name="pencil" size="small" onClick={this.openModal} /> <Icon name="pencil" size="small" onClick={this.openModal} />
)} )}
</Responsive> </Responsive>
<Responsive maxWidth={768}>
{this.props.type === "new" ? (
<Button icon fluid labelPosition="left" onClick={this.openModal}>
<Icon name="plus" size="small" />
ADD ROOM
</Button>
) : (
<Icon name="pencil" size="small" onClick={this.openModal} />
)}
</Responsive>
<Responsive maxWidth={768}> <Responsive maxWidth={768}>
{this.props.type === "new" ? ( {this.props.type === "new" ? (
<Button icon fluid labelPosition="left" onClick={this.openModal}> <Button icon fluid labelPosition="left" onClick={this.openModal}>
@ -124,12 +152,20 @@ export default class ModalWindow extends Component {
</Form.Field> </Form.Field>
<p>Insert an image of the room:</p> <p>Insert an image of the room:</p>
<Form.Field> <Form.Field>
<Input <Image
src={this.state.img == null ? NO_IMAGE : this.state.img}
size="small"
onClick={() => this.fileInputRef.current.click()}
/>
<input
ref={this.fileInputRef}
hidden
label="Room image" label="Room image"
type="file" type="file"
name="img" name="img"
onChange={this.changeSomething} accept="image/png, image/jpeg"
value={this.state.img} onChange={this.getBase64.bind(this)}
/> />
</Form.Field> </Form.Field>
</Form> </Form>
@ -174,18 +210,6 @@ export default class ModalWindow extends Component {
<Icon name="checkmark" />{" "} <Icon name="checkmark" />{" "}
{this.props.type === "new" ? "Add room" : "Save changes"} {this.props.type === "new" ? "Add room" : "Save changes"}
</Button> </Button>
<Button
color="green"
onClick={
this.props.type === "new"
? this.addRoomModal
: this.modifyRoomModal
}
>
<Icon name="checkmark" />{" "}
{this.props.type === "new" ? "Add room" : "Save changes"}
</Button>
</Modal.Actions> </Modal.Actions>
</Modal> </Modal>
</div> </div>