aboutsummaryrefslogtreecommitdiffstats
path: root/client/src/ui/Selection.js
blob: 5e2fe66ddc0d1fbc436cbf9761068859fddaa208 (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { h } from 'preact';
import { useState, useEffect } from 'preact/hooks';
import cn from 'classnames';
import { useDispatch } from '../actions';
import css from './css';
import { Note } from './Note';

css`
.drawer {
	position: fixed;
	inset: 0;
	top: auto;

	z-index: 200;
	background: var(--theme-note-fg);

	/* wtf webkit */
  -webkit-backface-visibility: hidden;
}

.drawer .handle {
	height: 1.5rem;
}

.drawer .handle button {
	display: block;

	height: 1rem;
	line-height: 1rem;
	margin: -1rem auto 0;
	padding: 0.25rem;
	background: var(--theme-note-bg);
	border-radius: 0.2rem;
}

.drawer .scroller {
	display: flex;
	overflow: auto;
	width: 100%;
	padding: 1rem 0;

	transition: max-height 0.3s;
}

.drawer .contents {
	display: flex;

	align-items: flex-start;

	gap: 1rem;
	padding: 0 1.5rem;
}

.drawer .contents > * {
	flex: 0 0 auto;
}

.drawer .contents > .reply {
	display: flex;
	flex-direction: column;
	align-self: stretch;
}

.drawer .contents > .reply textarea {
	flex: 1 1;
}
`;

export const Drawer = ({ height, children }) => {
	const [ hidden, setHidden ] = useState(true);

	return (
		<div class="drawer">
			<div class="handle">
				<button onClick={() => setHidden(!hidden)}>
					###
				</button>
			</div>
			<div
				class="scroller"
				style={{
					height,
					'max-height': hidden ? '1rem' : height,
				}}
			>
				<div class="contents">
					{children}
				</div>
			</div>
		</div>
	);
};

export const Selection = ({ items, toggleSelected }) => {
	const [reply, setReply] = useState('');
	const dispatch = useDispatch();

	return (
		<Drawer height="8.55rem" >
			{items.map((item) => (
				<Note
					{...item}
					ellipsis
					onSelect={toggleSelected}
				/>
			))}
			{!!items.length && (
				<div class="reply">
					<textarea value={reply} onChange={(e) => setReply(e.target.value)} />
					<button onClick={() => {
						dispatch({
							type: 'reply',
							content: reply,
							to: items.map(i => i.id),
						})
						.then(() => setReply(''));
					}}>
						reply
					</button>
				</div>
			)}
		</Drawer>
	);
};