blob: 83b1a2aa821ad9730a74ad5122f8794f67fa4f54 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
import React, {useContext} from 'react';
import Context from 'context';
import useNotes from '../hooks/useNotes'
import {removeNote} from '../helpers/noteActions.js'
import copyToClipboard from '../helpers/copyToClipboard.js'
const NoteView = ({fetchedNote, setFetchedNote, setAction}) => {
const {mutateNotes} = useNotes()
const {setPopup} = useContext(Context)
if (!fetchedNote) return <p>Loading...</p>
if (fetchedNote.error) {
setFetchedNote()
setAction('')
}
const {_id, content, title} = fetchedNote
return (
<section>
<div className='window__submenu'>
<div onClick={() => { setFetchedNote(); setAction('') }}>Back</div>
<div onClick={() => copyToClipboard(content, setPopup)}>Copy</div>
<div onClick={() => { setAction('editNote')}}>Edit</div>
<div onClick={e => { removeNote(e, _id, mutateNotes, setPopup, setAction) }}>Remove</div>
</div>
<div className='window__scroll'>
<h2 className='selectable'>{title}</h2>
<p className='selectable'>{content}</p>
</div>
<style jsx>{`
section {
background: white;
padding: 1rem;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
animation: fade-in .3s;
}
@keyframes fade-in {
from {opacity: 0;}
to {opacity: 1;}
}
h2 {
font-size: 1.25em;
font-weight: 600;
padding: 1rem;
}
p {
padding: 0 1rem 1rem;
white-space: pre-line;
}
`}</style>
</section>
)
}
export default NoteView
|