-
Notifications
You must be signed in to change notification settings - Fork 4
/
CustomListEditor.tsx
313 lines (290 loc) · 9.8 KB
/
CustomListEditor.tsx
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
import * as React from "react";
import { Button, Panel } from "library-simplified-reusable-components";
import { CollectionData } from "@thepalaceproject/web-opds-client/lib/interfaces";
import {
AdvancedSearchQuery,
LanguagesData,
LibraryData,
CollectionData as AdminCollectionData,
} from "../interfaces";
import {
CustomListEditorProperties,
CustomListEditorEntriesData,
CustomListEditorSearchParams,
} from "../reducers/customListEditor";
import CustomListEntriesEditor from "./CustomListEntriesEditor";
import CustomListSearch from "./CustomListSearch";
import EditableInput from "./EditableInput";
import ShareButton from "./ShareButton";
import TextWithEditMode from "./TextWithEditMode";
import ShareIcon from "./icons/ShareIcon";
export type CustomListEditorProps = {
autoUpdateStatus?: string;
collections?: AdminCollectionData[];
entries?: CustomListEditorEntriesData;
entryPoints?: string[];
isAutoUpdateEnabled?: boolean;
isFetchingMoreCustomListEntries: boolean;
isFetchingSearchResults: boolean;
isFetchingMoreSearchResults: boolean;
isLoaded?: boolean;
isModified?: boolean;
isSearchModified?: boolean;
isOwner?: boolean;
isShared?: boolean;
isSharePending?: boolean;
isValid?: boolean;
languages: LanguagesData;
library: LibraryData;
listId?: string;
properties?: CustomListEditorProperties;
savedName?: string;
searchParams?: CustomListEditorSearchParams;
searchResults?: CollectionData;
startingTitle?: string;
addAllEntries?: () => void;
addEntry?: (id: string) => void;
deleteAllEntries?: () => void;
deleteEntry?: (id: string) => void;
loadMoreEntries: () => void;
loadMoreSearchResults: () => void;
reset?: () => void;
save: () => void;
search: () => void;
share?: () => Promise<void>;
toggleCollection?: (id: number) => void;
updateProperty?: (name: string, value) => void;
updateSearchParam?: (name: string, value) => void;
addAdvSearchQuery?: (builderName: string, query: AdvancedSearchQuery) => void;
updateClearFiltersFlag?: (builderName: string, value: boolean) => void;
updateAdvSearchQueryBoolean?: (
builderName: string,
id: string,
bool: string
) => void;
moveAdvSearchQuery?: (
builderName: string,
id: string,
targetId: string
) => void;
removeAdvSearchQuery?: (builderName: string, id: string) => void;
selectAdvSearchQuery?: (builderName: string, id: string) => void;
};
export default function CustomListEditor({
autoUpdateStatus,
collections,
entries,
entryPoints,
isAutoUpdateEnabled,
isFetchingMoreCustomListEntries,
isFetchingSearchResults,
isFetchingMoreSearchResults,
isLoaded,
isModified,
isSearchModified,
isOwner,
isShared,
isSharePending,
isValid,
languages,
library,
listId,
properties,
savedName,
searchParams,
searchResults,
startingTitle,
addAllEntries,
addEntry,
deleteAllEntries,
deleteEntry,
loadMoreEntries,
loadMoreSearchResults,
reset,
save,
search,
share,
toggleCollection,
updateProperty,
updateSearchParam,
addAdvSearchQuery,
updateClearFiltersFlag,
updateAdvSearchQueryBoolean,
moveAdvSearchQuery,
removeAdvSearchQuery,
selectAdvSearchQuery,
}: CustomListEditorProps) {
const { collections: listCollections, name } = properties;
// Automatically execute the search when the list being edited changes, or finishes loading
// (which means a stored query may have been loaded).
React.useEffect(() => {
search?.();
}, [listId, isLoaded]);
const readOnly = !isOwner;
const opdsFeedUrl =
listId && savedName
? `${library?.short_name}/lists/${savedName}/crawlable`
: undefined;
return (
<div className="custom-list-editor">
<div className="custom-list-editor-header">
<div className="edit-custom-list-title">
{readOnly && <h3>{name}</h3>}
{!readOnly && (
<fieldset className="save-or-edit">
<legend className="visuallyHidden">List name</legend>
<TextWithEditMode
text={name}
placeholder="list title"
onUpdate={(title) => updateProperty?.("name", title)}
aria-label="Enter a title for this list"
disableIfBlank={true}
/>
</fieldset>
)}
{listId && <h4>ID-{listId}</h4>}
</div>
{!readOnly && (
<div className="save-or-cancel-list">
<Button
callback={save}
disabled={!isModified || !isValid}
content="Save this list"
/>
<Button
className="inverted"
callback={reset}
disabled={!isModified}
content="Cancel changes"
/>
</div>
)}
</div>
<div className="custom-list-editor-body">
<section>
{listId && (
<Panel
headerText="Sharing"
id="sharing"
content={
isOwner ? (
<div className="sharing-info">
<p className="sharing-status">
{isShared ? "Shared " : "Not shared"}
{isShared && <ShareIcon />}
</p>
<p>
{isShared
? "This list has been shared with other libraries."
: "This list can be shared with the other libraries that are currently configured in this Collection Manager."}{" "}
A shared list may be edited only by the owning library.
Each library that is subscribed to a shared list will
obtain only the titles that are available to that library.
</p>
<p>
<i>Once shared, a list cannot be unshared or deleted.</i>
</p>
{isShared && (
<p>
Sharing this list again will make it available to any
libraries that have been registered in this Collection
Manager since the list was last shared.
</p>
)}
<ShareButton
disabled={isSharePending}
pending={isSharePending}
submit={share}
text={isShared ? "Share again" : "Share"}
/>
</div>
) : (
<div className="sharing-info">
<p className="sharing-status">
<ShareIcon /> Subscribed
</p>
<p>
This list has been shared by another library. It may be
edited only by the owning library. Only the titles in the
shared list that are available to this library will be
obtained.
</p>
</div>
)
}
/>
)}
{collections?.length > 0 && (
<div className="custom-list-filters">
<Panel
headerText="Add from collections"
id="add-from-collections"
content={
<div className="collections">
<div>
Automatically add new books from these collections to this
list:
</div>
{collections.map(({ id, name }) => (
<EditableInput
disabled={readOnly}
key={id}
type="checkbox"
name="collection"
checked={listCollections.includes(id)}
label={name}
value={id}
onChange={(id) => toggleCollection?.(parseInt(id))}
/>
))}
</div>
}
/>
</div>
)}
<CustomListSearch
autoUpdate={properties.autoUpdate}
isOwner={isOwner}
listId={listId}
searchParams={searchParams}
updateAutoUpdate={(value) => updateProperty?.("autoUpdate", value)}
updateSearchParam={updateSearchParam}
search={search}
entryPoints={entryPoints}
startingTitle={startingTitle}
library={library}
languages={languages}
showAutoUpdate={isAutoUpdateEnabled}
addAdvSearchQuery={addAdvSearchQuery}
updateClearFiltersFlag={updateClearFiltersFlag}
updateAdvSearchQueryBoolean={updateAdvSearchQueryBoolean}
moveAdvSearchQuery={moveAdvSearchQuery}
removeAdvSearchQuery={removeAdvSearchQuery}
selectAdvSearchQuery={selectAdvSearchQuery}
/>
</section>
<CustomListEntriesEditor
autoUpdateStatus={autoUpdateStatus}
autoUpdate={properties.autoUpdate}
isOwner={isOwner}
isSearchModified={isSearchModified}
searchResults={searchResults}
entries={entries.current}
loadMoreSearchResults={loadMoreSearchResults}
loadMoreEntries={loadMoreEntries}
isFetchingSearchResults={isFetchingSearchResults}
isFetchingMoreSearchResults={isFetchingMoreSearchResults}
isFetchingMoreCustomListEntries={isFetchingMoreCustomListEntries}
opdsFeedUrl={opdsFeedUrl}
entryCount={entries.currentTotalCount}
listId={listId}
addEntry={addEntry}
addAllEntries={addAllEntries}
deleteEntry={deleteEntry}
deleteAllEntries={deleteAllEntries}
refreshResults={search}
/>
</div>
</div>
);
}