import React, { Component, useState } from "react"; import Form from 'react-bootstrap/Form' import Button from 'react-bootstrap/Button'; import Table from 'react-bootstrap/Table'; import axios from 'axios'; export default class Createsong extends Component { constructor(props) { super(props) // Setting up functions this.onChangePlaylistIndex = this.onChangePlaylistIndex.bind(this); this.onChangePlaylistType = this.onChangePlaylistType.bind(this); this.onChangePlaylistTitle = this.onChangePlaylistTitle.bind(this); this.onChangePlaylistlink = this.onChangePlaylistlink.bind(this); this.onChangePlaylistImgurl = this.onChangePlaylistImgurl.bind(this); this.onChangePlaylistcolor = this.onChangePlaylistcolor.bind(this); this.onChangePlaylistArtist = this.onChangePlaylistArtist.bind(this); //songdata this.onChangeSongIndex = this.onChangeSongIndex.bind(this); this.onChangeSongName = this.onChangeSongName.bind(this); this.onChangeSongImage = this.onChangeSongImage.bind(this); this.onChangeSongLink = this.onChangeSongLink.bind(this); this.onSubmit = this.onSubmit.bind(this); // Setting up state this.state = { index: '', type: '', title: '', link: '', imgUrl: '', color: '', artist: '', //song songindex:'', songname:'', songimage:'', songlink:'' } } onChangePlaylistIndex(e) { this.setState({ index: e.target.value }) } onChangePlaylistType(e) { this.setState({ type: e.target.value }) } onChangePlaylistTitle(e) { this.setState({ title: e.target.value }) } onChangePlaylistlink(e) { this.setState({ link: e.target.value }) } onChangePlaylistImgurl(e) { this.setState({ imgUrl: e.target.value }) } onChangePlaylistcolor(e) { this.setState({ color: e.target.value }) } onChangePlaylistArtist(e) { this.setState({ artist: e.target.value }) } //song onChangeSongIndex(e) { this.setState({ songindex: e.target.value }) } onChangeSongName(e) { this.setState({ songname: e.target.value }) } onChangeSongImage(e) { this.setState({ songimage: e.target.value }) } onChangeSongLink(e) { this.setState({ songlink: e.target.value }) } onSubmit(e) { e.preventDefault() const songObject = { index: this.state.index, type: this.state.type, title: this.state.title, link: this.state.link, imgUrl: this.state.imgUrl, color: this.state.color, artist: this.state.artist, songdata: [{songindex: this.state.songindex, songname: this.state.songname, songimage: this.state.songimage, songlink: this.state.songlink,}], }; axios.post('https://react-mernstack-crud-1.cocodisme.repl.co/songs/create-song', songObject) .then(res => console.log(res.data)); this.setState({ index: '', type: '', title: '', link: '', imgUrl: '', color: '', artist: '', songindex: '', songname: '', songimage: '', songlink: '', }) } render() { return (
Index Type Title Audio Poster Artist Name Color
index songname songimage songlink Add Remove
); } }