-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE : Include an existing image into an existing collection
- Loading branch information
1 parent
5a6e9be
commit 1fe818a
Showing
8 changed files
with
184 additions
and
22 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function (doc) { | ||
if ( doc.links.filter(e => e.verb === 'includes').length > 0 ){ | ||
emit(doc.dc_title, doc); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import {FolderPlus} from 'react-bootstrap-icons'; | ||
import Card from 'react-bootstrap/Card'; | ||
import {useState} from 'react'; | ||
import ExistingCollection from './ExistingCollection'; | ||
import FutureCollection from './FutureCollection'; | ||
|
||
function CollectionList({relatedTo, setLastUpdate, backend, collections}) { | ||
const [showList, setShowList] = useState(false); | ||
const [searchQuery, setSearchQuery] = useState(''); | ||
|
||
const handleShowList = () => { | ||
setShowList(!showList); | ||
}; | ||
|
||
const handleSearchChange = (event) => { | ||
setSearchQuery(event.target.value); | ||
}; | ||
|
||
const filteredCollections = collections.filter(collection => | ||
collection.value.dc_title.toLowerCase().includes(searchQuery.toLowerCase()) | ||
); | ||
|
||
return ( | ||
<div> | ||
<Card className="h-100"> | ||
<Card.Body className="text-center"> | ||
<FolderPlus | ||
className="icon addCollection" onClick={handleShowList} | ||
/> | ||
</Card.Body> | ||
</Card> | ||
{showList && ( | ||
<div> | ||
<Card className="h-100"> | ||
<Card.Body> | ||
<input | ||
type="text" | ||
placeholder="Search collections" | ||
value={searchQuery} | ||
onChange={handleSearchChange} | ||
className="form-control" | ||
/> | ||
</Card.Body> | ||
</Card> | ||
<FutureCollection relatedTo={relatedTo} {...{setLastUpdate, backend}} /> | ||
{filteredCollections.map(collection => ( | ||
<ExistingCollection | ||
key={collection.id} | ||
relatedTo={relatedTo} | ||
collection={collection} | ||
setShowList={setShowList} | ||
{...{setLastUpdate, backend}} | ||
/> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export default CollectionList; |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import '../styles/ExistingCollection.css'; | ||
import Card from 'react-bootstrap/Card'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
function ExistingCollection({relatedTo, collection, setLastUpdate, backend, setShowList}) { | ||
const navigate = useNavigate(); | ||
const id = collection._id; | ||
const title = extractSubstring(collection.value.dc_title); | ||
|
||
let handleClick = async () => { | ||
let newLink = {verb: 'includes', object: relatedTo[0]}; | ||
let updatedLinks = [...collection.value.links, newLink]; | ||
backend.putDocument({ | ||
...collection.value, | ||
links: updatedLinks | ||
}).then(() => { | ||
setLastUpdate(collection.value._id); | ||
navigate((relatedTo.length ? '#' : '/') + collection.value._id); | ||
}); | ||
setShowList(false); | ||
}; | ||
|
||
return ( | ||
<Card onClick={handleClick} className="existingCollection collectionList"> | ||
<Card.Body> | ||
<span>{title}</span> | ||
</Card.Body> | ||
</Card> | ||
); | ||
} | ||
|
||
function extractSubstring(str) { | ||
if (str.includes('–')) { | ||
str = str.split('–')[0]; | ||
} | ||
|
||
if (str.length > 25) { | ||
str = str.substring(0, 25) + '...'; | ||
} | ||
|
||
return str; | ||
} | ||
|
||
export default ExistingCollection; |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useNavigate } from 'react-router-dom'; | ||
import Card from 'react-bootstrap/Card'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
function FutureCollection({relatedTo, setLastUpdate, backend}) { | ||
const navigate = useNavigate(); | ||
|
||
let handleClick = async () => { | ||
let _id = uuidv4(); | ||
let editors = [backend.credentials.name]; | ||
let links = relatedTo.map(object => ({verb: 'includes', object})); | ||
backend.putDocument({ | ||
_id, | ||
editors, | ||
dc_creator: '<CREATOR>', | ||
dc_title: '<TITLE>', | ||
dc_issued: new Date(), | ||
text: '', | ||
dc_license: 'https://creativecommons.org/licenses/by-sa/4.0/', | ||
links | ||
}) | ||
.then((x) => { | ||
setLastUpdate(_id); | ||
navigate((relatedTo.length ? '#' : '/') + _id); | ||
}); | ||
}; | ||
|
||
return ( | ||
<Card className="h-100"> | ||
<Card.Body className="creation"> | ||
<span title="Create a collection from this document" className="icon create-collection" onClick={handleClick}>Create a new Collection.</span> | ||
</Card.Body> | ||
</Card> | ||
); | ||
} | ||
|
||
export default FutureCollection; |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.existingCollection { | ||
height: 56px !important; | ||
width: inherit; | ||
justify-content: center; | ||
align-items: center; | ||
overflow: hidden; /* hide content outside the container */ | ||
white-space: nowrap; /* disallow text wrapping */ | ||
} |