-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8388d94
commit fedcfbe
Showing
35 changed files
with
236 additions
and
219 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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { useState } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
export const FILTER_OPTIONS = { | ||
all: 'all', | ||
thisTab: 'thisTab', | ||
unsorted: 'unsorted', | ||
}; | ||
|
||
export const SORT_OPTIONS = { | ||
abc: 'abc', | ||
zxy: 'zxy', | ||
color: 'color', | ||
newest: 'newest', | ||
oldest: 'oldest', | ||
}; | ||
|
||
export const VIEW_OPTIONS = { | ||
condensed: 'condensed', | ||
expanded: 'expanded', | ||
}; | ||
|
||
export const useLibraryHooks = () => { | ||
const activeTab = useSelector(state => state.campaignData.present.activeViewId); | ||
const tabOrder = useSelector(state => state.campaignData.present.viewOrder); | ||
const cardCollection = useSelector(state => state.campaignData.present.cards); | ||
|
||
const [isOpen, setIsOpen] = useState(false); | ||
const [searchString, setSearchString] = useState(''); | ||
const [filterOption, setFilterOption] = useState(FILTER_OPTIONS.all); | ||
const [sortOption, setSortOption] = useState(SORT_OPTIONS.abc); | ||
const [viewOption, setViewOption] = useState(VIEW_OPTIONS.condensed); | ||
|
||
let libraryCards = []; | ||
const search = searchString.toLowerCase(); | ||
for (let id in cardCollection) { | ||
const title = cardCollection[id].title ?? ''; | ||
const text = cardCollection[id].content?.text ?? ''; | ||
if (title.toLowerCase().includes(search) || text.toLowerCase().includes(search)) { | ||
switch (filterOption) { | ||
case FILTER_OPTIONS.all: | ||
libraryCards = [ ...libraryCards, id ]; | ||
break; | ||
case FILTER_OPTIONS.thisTab: | ||
if (cardCollection[id].views?.[activeTab]) { | ||
libraryCards = [ ...libraryCards, id ]; | ||
} | ||
break; | ||
case FILTER_OPTIONS.unsorted: | ||
const tabsOfCard = Object.keys(cardCollection[id].views); | ||
const intersection = tabOrder.filter(tab => tabsOfCard.includes(tab)) | ||
if (intersection.length === 0) { | ||
libraryCards = [ ...libraryCards, id ]; | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return { | ||
isOpen, | ||
toggleLibrary: () => setIsOpen(!isOpen), | ||
setSearchString, | ||
setFilterOption, | ||
setSortOption, | ||
setViewOption, | ||
libraryCards, | ||
}; | ||
}; |
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,55 @@ | ||
import React from 'react'; | ||
|
||
import LibraryCard from '../Card/LibraryCard'; | ||
import LibrarySearch from './LibrarySearch'; | ||
|
||
import { useLibraryHooks } from './hooks'; | ||
|
||
import './index.scss'; | ||
import LibraryIcon from '../../assets/icons/library.svg'; | ||
|
||
const Library = () => { | ||
const { | ||
isOpen, | ||
toggleLibrary, | ||
setSearchString, | ||
setFilterOption, | ||
setSortOption, | ||
setViewOption, | ||
libraryCards, | ||
} = useLibraryHooks(); | ||
|
||
let cardComponents = []; | ||
for (let id in libraryCards) { | ||
cardComponents = [ | ||
...cardComponents, | ||
<LibraryCard key={id} cardId={id} />, | ||
]; | ||
} | ||
|
||
return ( | ||
<div className={`library ${isOpen ? 'open': 'close'}`}> | ||
<div className='library-panel'> | ||
<LibrarySearch /> | ||
{/* | ||
TODO remove LibrarySearch and expand out its functionality to the following. | ||
Make changes to the hooks file to change filtering and sorting | ||
Change names of components if need be | ||
*/} | ||
{/* <SearchBar setSearchString={setSearchString} /> */} | ||
{/* <FilterBar setFilterOption={setFilterOption} /> */} | ||
{/* <SortBar setSortOption={setSortOption} /> */} | ||
{/* <ViewBar setViewOption={setViewOption} /> */} | ||
{/* <div className='library-card-container'> | ||
{cardComponents} | ||
</div> */} | ||
</div> | ||
<button className='library-btn' onClick={toggleLibrary}> | ||
<img src={LibraryIcon} alt='Library' /> | ||
<span className='tooltip'>Library</span> | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Library; |
Oops, something went wrong.