-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from sereneinserenade/new-note-previews
[feat] Revamped the NotePreviews in Sidebar
- Loading branch information
Showing
8 changed files
with
208 additions
and
165 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
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
Empty file.
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,124 @@ | ||
import React, { useCallback, useRef, useState } from 'react'; | ||
import { Button, Tooltip, Text } from '@nextui-org/react'; | ||
|
||
import { Note } from '../../types'; | ||
|
||
import './styles/NotePreview.scss' | ||
import { FiCheck, FiEdit2, FiTrash2 } from 'react-icons/fi'; | ||
import { stopPrevent } from '../../utils'; | ||
import { RiRecycleLine } from 'react-icons/ri'; | ||
|
||
interface NotePreviewProps { | ||
onClick: Function, | ||
note: Note, | ||
activeNote: Note | undefined, | ||
initiateMoveToBin: Function, | ||
returnFormattedDateString: Function | ||
setNoteTitle: Function | ||
isBin: boolean | ||
|
||
initiateRecycleNote?: Function | ||
initiateDeletePermanently?: Function | ||
} | ||
|
||
const GetNoteTitle = (note: Note, isInBin = false, setNoteTitle: Function) => { | ||
const [isEditable, setIsEditable] = useState(false) | ||
|
||
const [name, setName] = useState(`${note.title}`) | ||
|
||
const inputRef = useRef(null) | ||
|
||
const onInput = useCallback(() => { | ||
setNoteTitle(note, name, isInBin) | ||
setIsEditable(false) | ||
}, [name, note, isInBin]) | ||
|
||
const onEditStart = useCallback(() => { | ||
setIsEditable(true); | ||
|
||
setTimeout(() => (inputRef.current as unknown as HTMLInputElement).focus()) | ||
}, []) | ||
|
||
return ( | ||
<span className='title-editor-container flex'> | ||
{ | ||
!isInBin | ||
&& ( | ||
<span className='control-buttons'> | ||
{isEditable | ||
? <Tooltip placement='topStart' content={<Text> Save Title <kbd>Enter</kbd></Text>}><FiCheck onClick={(e) => stopPrevent(e) && onInput()} /> </Tooltip> | ||
: <Tooltip placement='topStart' content={'Edit Title'}><FiEdit2 onClick={(e) => stopPrevent(e) && onEditStart()} /> </Tooltip> | ||
} | ||
</span> | ||
) | ||
} | ||
|
||
<input | ||
placeholder='Add Title...' | ||
className='title-editor-input' | ||
onClick={e => e.stopPropagation()} | ||
value={name} | ||
onInput={e => setName((e.target as any).value)} | ||
disabled={!isEditable} | ||
onKeyPress={(e) => e.code === 'Enter' && onInput()} | ||
ref={inputRef} | ||
/> | ||
</span> | ||
) | ||
} | ||
|
||
export const NotePreview: React.FC<NotePreviewProps> = ({ | ||
onClick, | ||
note, | ||
activeNote, | ||
initiateMoveToBin, | ||
returnFormattedDateString, | ||
setNoteTitle, | ||
isBin, | ||
initiateRecycleNote, | ||
initiateDeletePermanently | ||
}) => { | ||
return ( | ||
<article | ||
onClick={() => onClick(note)} | ||
key={note.id + 'internal'} | ||
className={`sidebar-note flex flex-row justify-between align-center ${note.id === activeNote?.id ? 'active' : ''}`} | ||
> | ||
<section className='title-and-action-center flex' aria-label='title-and-action-center'> | ||
{GetNoteTitle(note, isBin, setNoteTitle)} | ||
<Text size={12}> {returnFormattedDateString(new Date(note.timestamp))} </Text> | ||
</section> | ||
|
||
{ | ||
isBin && ( | ||
<Tooltip | ||
placement='top' | ||
content={'Recycle'}> | ||
<Button | ||
color="primary" | ||
auto | ||
ghost | ||
size='sm' | ||
onClick={(e) => initiateRecycleNote?.(e, note)} | ||
icon={<RiRecycleLine />} | ||
/> | ||
</Tooltip> | ||
) | ||
} | ||
|
||
<Tooltip | ||
placement='right' | ||
content={'Move to Bin'} | ||
> | ||
<Button | ||
color="error" | ||
auto | ||
ghost | ||
size='sm' | ||
onClick={(e) => isBin ? initiateDeletePermanently?.(e, note) : initiateMoveToBin(e, note)} | ||
icon={<FiTrash2 />} | ||
/> | ||
</Tooltip> | ||
</article> | ||
) | ||
} |
Oops, something went wrong.