-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new collection and edit collection title
- Loading branch information
Jaagrav
committed
Jul 27, 2021
1 parent
8a24b36
commit 76d1999
Showing
2 changed files
with
77 additions
and
14 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 |
---|---|---|
@@ -1,24 +1,60 @@ | ||
import React, {useEffect, useState} from "react"; | ||
import React, {useEffect, useState, useRef} from "react"; | ||
|
||
import {Draggable} from "react-beautiful-dnd"; | ||
|
||
import BookMarksItem from "./bookmarks.js"; | ||
|
||
import {FiPlus, FiTrash2} from "react-icons/fi"; | ||
import {MdApps} from "react-icons/md"; | ||
|
||
export default function Collection({entities, setEntities, collectionId, index}) { | ||
const [collectionTitle, setCollectionTitle] = useState(entities.collections[collectionId].title), | ||
collectionTitleRef = useRef(); | ||
|
||
const deleteCollection = () => { | ||
let collections = entities.collections; | ||
delete collections[collectionId]; | ||
|
||
let collectionOrder = entities.collectionOrder; | ||
collectionOrder.splice(collectionOrder.indexOf(collectionId), 1); | ||
|
||
setEntities({ ...entities, collections, collectionOrder }); | ||
} | ||
|
||
useEffect(() => { | ||
let collections = entities.collections; | ||
collections[collectionId].title = collectionTitle; | ||
|
||
setEntities({...entities, collections}); | ||
}, [collectionTitle]); | ||
|
||
return ( | ||
<Draggable draggableId={entities.collections[collectionId].id} index={index} isDragDisabled={false}> | ||
<> | ||
{ | ||
provided => ( | ||
<div className="h-[305px] mb-8 rounded-lg dark:bg-[#ffffff20] border-b-[1px] border-[#eeeeee30]" {...provided.draggableProps} ref={provided.innerRef} style={provided.draggableProps.style}> | ||
<div className="h-full w-full p-4"> | ||
<h1 {...provided.dragHandleProps} className="text-2xl font-bold text-[#fff]">{entities.collections[collectionId].title}</h1> | ||
<div className="h-full w-full"> | ||
<BookMarksItem collectionId={collectionId} bookmarkData={entities.bookmarks} bookmarkIDs={entities.collections[collectionId].bookmarkIDs} entities={entities} setEntities={setEntities}/> | ||
entities.collections[collectionId].id && <Draggable draggableId={entities.collections[collectionId].id} index={index} isDragDisabled={false}> | ||
{ | ||
provided => ( | ||
<div className="h-[305px] mb-8 rounded-lg bg-[#ffffff20] dark:bg-[#ffffff20] border-b-[1px] border-[#eeeeee30]" {...provided.draggableProps} ref={provided.innerRef} style={provided.draggableProps.style}> | ||
<div className="h-full w-full p-4"> | ||
<div className="flex items-center justify-between"> | ||
<div className="" {...provided.dragHandleProps}> | ||
<MdApps className="mb-1 mr-2 text-white text-xl" style={{transform: 'rotate(90deg)'}} /> | ||
</div> | ||
<input spellCheck={false} value={collectionTitle} onChange={(e) => setCollectionTitle(e.target.value)} className="text-2xl w-full font-bold text-[#fff] bg-transparent cursor-text" /> | ||
<div className="flex items-center justify-between"> | ||
<FiTrash2 className="text-white text-lg cursor-pointer ml-2" onClick={deleteCollection} /> | ||
<FiPlus className="text-white text-lg cursor-pointer ml-2" /> | ||
</div> | ||
</div> | ||
<div className="h-full w-full"> | ||
<BookMarksItem collectionId={collectionId} bookmarkData={entities.bookmarks} bookmarkIDs={entities.collections[collectionId].bookmarkIDs} entities={entities} setEntities={setEntities}/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
) | ||
} | ||
</Draggable> | ||
} | ||
</Draggable> | ||
</> | ||
) | ||
} |
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