-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring more of the components with using pageviews
- Loading branch information
Eimi Okuno
authored and
Eimi Okuno
committed
Sep 27, 2019
1 parent
22b49a5
commit e32536c
Showing
15 changed files
with
680 additions
and
261 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,57 @@ | ||
import React, { useState } from 'react'; | ||
import React, { useState, useEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import SimpleCard from '../SimpleCard'; | ||
import SearchBar from './SearchBar'; | ||
import TranscriptCard from '../TranscriptCard'; | ||
|
||
const List = (props) => { | ||
|
||
const [ items, setItems ] = useState(props.items); | ||
|
||
const includesText = (text, subsetText) => { | ||
return text.toLowerCase().includes(subsetText.toLowerCase().trim()); | ||
}; | ||
|
||
const handleDeleteItem = (itemId) => { | ||
const updatedList = items.filter((item) => { | ||
return item.id !== itemId; | ||
}); | ||
props.handleDelete(itemId); | ||
setItems(updatedList); | ||
}; | ||
|
||
const handleDisplay = (item, searchText) => { | ||
if ( | ||
includesText(item.title, searchText) || | ||
includesText(item.description, searchText) | ||
) { | ||
item.display = true; | ||
} else { | ||
item.display = false; | ||
useEffect(() => { | ||
if (items.length === 0) { | ||
setItems(props.items); | ||
} | ||
|
||
return item; | ||
}; | ||
return () => { | ||
|
||
const handleSearchItem = searchText => { | ||
const results = items.filter(item => handleDisplay(item, searchText)); | ||
setItems(results); | ||
}; | ||
}; | ||
}, [ props.items ]); | ||
|
||
const listItems = items.map((item) => { | ||
if (item.display && item.status) { | ||
return ( | ||
<TranscriptCard | ||
{ ...item } | ||
handleEdit={ props.handleEdit(item.id) } | ||
handleDelete={ handleDeleteItem } | ||
key={ item.key } | ||
handleEditItem={ props.handleEditItem } | ||
handleDeleteItem={ props.handleDeleteItem } | ||
/> | ||
); | ||
} | ||
else if (item.display) { | ||
return ( | ||
<SimpleCard | ||
{ ...item } | ||
handleEdit={ props.handleEdit(item.id) } | ||
handleDelete={ handleDeleteItem } | ||
key={ item.key } | ||
handleEditItem={ props.handleEditItem } | ||
handleDeleteItem={ props.handleDeleteItem } | ||
/> | ||
);} | ||
|
||
return null; | ||
}).filter(item => { | ||
return item !== null; | ||
}); | ||
|
||
return ( | ||
<section style={ { height: '75vh', overflow: 'scroll' } }> | ||
{items !== null && items.length !== 0 ? <SearchBar handleSearch={ handleSearchItem }/> : null} | ||
{listItems} | ||
</section> | ||
); | ||
}; | ||
|
||
List.propTypes = { | ||
items: PropTypes.array.isRequired, | ||
handleEdit: PropTypes.func.isRequired, | ||
handleDelete: PropTypes.func.isRequired, | ||
}; | ||
|
||
List.defaultProps = { | ||
items: [ | ||
{ | ||
id: '1234', | ||
key: 'abc123', | ||
title: 'Sample Simple Card Title One', | ||
description: 'This is a sample card description. This is fun!', | ||
display: true, | ||
url: '/projects/1/transcripts/5678' | ||
} | ||
], | ||
handleEdit: () => { | ||
console.log('Edit button clicked'); | ||
}, | ||
handleDelete: () => { | ||
console.log('Delete button clicked'); | ||
}, | ||
handleEditItem: PropTypes.func.isRequired, | ||
handleDeleteItem: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default List; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.