fix(editor): Task 3 round 1, literal journey, pin, limits, notice
This commit is contained in:
1 parent
8b42816270
commit
3bb3603115
9 files changed
+295
-97
No files matched your search
@@ -89,6 +89,15 @@ const positionOf = (all: readonly Reference[], key: ElementKey) =>
|
||||
|
||||
type Show = (key: ElementKey) => 'found' | 'none'
|
||||
|
||||
/** Whether the finding filter or the search hides `reference` from the list. */
|
||||
function hiddenBy(lib: ReferenceLibraryState, reference: Reference) {
|
||||
const cited = lib.finding && citedIds(lib.finding)
|
||||
return {
|
||||
filtered: !!cited && !cited.includes(reference.id),
|
||||
matches: referenceMatches(reference, lib.shown.view.query),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a reference's tile: opened, the search cleared (only it, P3) and the finding
|
||||
* filter removed when they hide it, its button focused after the commit that shows it
|
||||
@@ -102,14 +111,13 @@ function useShowReference(
|
||||
return (key) => {
|
||||
const at = positionOf(lib.all, key)
|
||||
if (at < 0) return 'none'
|
||||
const reference = lib.all[at]
|
||||
lib.tiles.reveal(lib.keys[at])
|
||||
const cited = lib.finding && citedIds(lib.finding)
|
||||
const filtered = !!cited && !cited.includes(reference.id)
|
||||
const matches = referenceMatches(reference, lib.shown.view.query)
|
||||
if (matches && !filtered) return focusRowLater(key) ? 'found' : 'none'
|
||||
if (filtered) layer.clearFilter()
|
||||
if (!matches) lib.shown.update({ query: '' })
|
||||
const hidden = hiddenBy(lib, lib.all[at])
|
||||
if (hidden.matches && !hidden.filtered) {
|
||||
return focusRowLater(key) ? 'found' : 'none'
|
||||
}
|
||||
if (hidden.filtered) layer.clearFilter()
|
||||
if (!hidden.matches) lib.shown.update({ query: '' })
|
||||
later(key)
|
||||
return 'found'
|
||||
}
|
||||
@@ -122,14 +130,21 @@ function useReferenceFocus(focus: FocusRequest | undefined, show: Show) {
|
||||
)
|
||||
}
|
||||
|
||||
/** The notice of a reference just added: shown until « Afficher », or until it is gone. */
|
||||
/**
|
||||
* The notice of a reference just added: shown until « Afficher », until it is gone, or
|
||||
* until the user leaves the References tab (it would be stale on their return).
|
||||
*/
|
||||
function useAddedNotice(
|
||||
all: readonly Reference[],
|
||||
added: ReferenceLayer['added'],
|
||||
show: Show,
|
||||
) {
|
||||
const [dismissed, setDismissed] = useState(0)
|
||||
const visible = usePlaceVisible()
|
||||
const reference = added && all.find((r) => r.id === added.id)
|
||||
if (added && !visible && dismissed !== added.serial) {
|
||||
setDismissed(added.serial)
|
||||
}
|
||||
if (!added || !reference || added.serial === dismissed) return null
|
||||
return {
|
||||
citation: reference.citation,
|
||||
|
||||
Reference in new issue
Block a user