Skip to content

Commit

Permalink
UI: Minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
SLaks committed Oct 20, 2024
1 parent 3c2e43e commit cc5047c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 27 deletions.
33 changes: 8 additions & 25 deletions src/components/ScrollDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ const { htmlToElement, purgeNode } = utils
*/
export class ScrollDisplay {
/** Renders an entry (from the view model) to the top of the scroll. */
readonly renderPrevious = this.generateRender({
insertStrategy: insertBefore,
})
readonly renderPrevious = this.generateRender('afterbegin')
/** Renders an entry (from the view model) to the bottom of the scroll. */
readonly renderNext = this.generateRender({ insertStrategy: insertAfter })
readonly renderNext = this.generateRender('beforeend')

// TODO(later): Remove after rewriting picker?
readonly rendered: Promise<void>
Expand Down Expand Up @@ -50,19 +48,15 @@ export class ScrollDisplay {
element.offsetTop + element.offsetHeight / 2 - this.root.offsetHeight / 2
}

private generateRender({
insertStrategy: insert,
}: {
insertStrategy: (parent: Element, child: Element) => void
}) {
private generateRender(insertPosition: InsertPosition) {
return (entry: RenderedEntry) => {
let node: Element
if (entry.type === 'message') {
node = renderMessageNode(entry)
} else {
node = renderPageNode(entry)
}
insert(this.root, node)
this.root.insertAdjacentElement(insertPosition, node)

return node
}
Expand All @@ -72,31 +66,20 @@ export class ScrollDisplay {
function renderPageNode(page: RenderedPageInfo) {
const node = document.createElement('div')
node.classList.add('tikkun-page')
if (page.run)
node.setAttribute('data-page-title', page.run.leining.date.title)
// TODO: Confirm safe to delete
// node.setAttribute('data-page-number', pageNumber.toString(10))
const el = htmlToElement(Page(page))

node.appendChild(el)
node.appendChild(htmlToElement(Page(page)))

return node
}

function renderMessageNode(entry: RenderedMessageInfo) {
const node = document.createElement('div')
node.classList.add('tikkun-message')

const span = document.createElement('span')
span.classList.add('tikkun-message-text')
node.appendChild(span)
span.textContent = entry.text
return node
}

const insertBefore = (parent: Element, child: Element) => {
parent.insertAdjacentElement('afterbegin', child)
}

const insertAfter = (parent: Element, child: Element) => {
parent.insertAdjacentElement('beforeend', child)
node.appendChild(span)
return node
}
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ const setVisibility = ({
}) => {
const classList = document.querySelector(selector).classList

classList[visible ? 'remove' : 'add']('u-hidden')
classList[visible ? 'remove' : 'add']('mod-animated')
classList.toggle('u-hidden', !visible)
classList.toggle('mod-animated', !visible)
}

const showParshaPicker = () => {
Expand Down

0 comments on commit cc5047c

Please sign in to comment.