Permalink
Browse files

single item contents populate

  • Loading branch information...
hwilliams13 committed Dec 3, 2019
1 parent f720406 commit e5cf773217dd52612fcc0d1c1ba3c4f92720264f
@@ -5,24 +5,24 @@
class ItemSerializer(serializers.ModelSerializer):
class Meta:
model = Item
fields = ('name', 'image', 'description', 'category', 'location', 'date_listed')
fields = ('id','name', 'image', 'description', 'category', 'location', 'date_listed')


class TradeSerializer(serializers.ModelSerializer):
items = ItemSerializer(many=True, read_only=True)
class Meta:
model = Trade
fields = ('time_stamp')
fields = ('id','time_stamp')


class MessageSerializer(serializers.ModelSerializer):
class Meta:
model = Message
fields = ('time_stamp', 'content', 'image')
fields = ('id','time_stamp', 'content', 'image')


class ConversationSerializer(serializers.ModelSerializer):
messages = MessageSerializer(many=True, read_only=True)
class Meta:
model = Conversation
fields = ('date_created')
fields = ('id','date_created')
@@ -102,6 +102,7 @@ class App extends React.Component {
refreshView = (e) => {
const previousState = {...this.state};
previousState.addNewItem = false;
previousState.showItem = false;
previousState.newItem.name = '';
previousState.newItem.image = '';
previousState.newItem.description = '';
@@ -111,13 +112,16 @@ class App extends React.Component {
}

showItemCommand = (e) => {
console.log(e.target);
const showItem = true;
this.setState({showItem: showItem});
const targetItemId = e.target.getAttribute("itemid");
const targetItemId = e.target.getAttribute("dataId");
console.log(targetItemId);
axios.get(`/api/v1/item/${targetItemId}`)
.then((res) => {
const targetItem = res.data;
this.setState({targetItem: targetItem});
console.log(res);
const targetItem = res.data;
this.setState({targetItem: targetItem});
})
}

@@ -6,7 +6,7 @@ class ItemTile extends React.Component {

render() {
return (
<div itemid={this.props.itemid} className="item-tile" style={{backgroundImage: `url(${this.props.image})`}} onClick={this.props.showItemCommand}>
<div dataId={this.props.dataId} className="item-tile" style={{backgroundImage: `url(${this.props.image})`}} onClick={this.props.showItemCommand}>
<p className="item-tile-name">{this.props.name}</p>
</div>
)
@@ -25,10 +25,11 @@ class MainFeed extends React.Component {
render() {
// console.log(this.props)
const itemList = this.props.itemList.map((item) => {
console.log(item);
// const itemList = this.itemList.map((item) => {
// console.log(item)
return (
<ItemTile itemid={item.id} name={item.name} image={item.image} showItemCommand={this.props.showItemCommand} />
<ItemTile dataId={item.id} name={item.name} image={item.image} showItemCommand={this.props.showItemCommand} />
)
})
return (
@@ -51,6 +52,7 @@ class MainFeed extends React.Component {
this.props.showItem ?
<SingleItem
targetItem={this.props.targetItem}
refreshView={this.props.refreshView}
/> :
null
}

0 comments on commit e5cf773

Please sign in to comment.