Skip to content

Commit

Permalink
fix(todo2): make task-list shadows depend on the scroll position
Browse files Browse the repository at this point in the history
  • Loading branch information
tatomyr committed Mar 24, 2024
1 parent 41c617f commit 5854ef0
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/examples/purity-todo/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ export type AppState = {
isSettingsModalOpen: boolean
taskDetailId?: string
tasks: Task[]
taskListElement: HTMLElement | null
}

export const initialState: AppState = {
view: "active",
input: "",
isSettingsModalOpen: false,
tasks: get({tasks: []}).tasks,
taskListElement: null,
}

export const state = {...initialState}
Expand Down
1 change: 0 additions & 1 deletion src/examples/purity-todo/components/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const headerStyle = (): string => render`
display: flex;
justify-content: space-around;
user-select: none;
box-shadow: 0px 4px 10px -2px;
}
</style>
Expand Down
1 change: 0 additions & 1 deletion src/examples/purity-todo/components/input-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const inputFormStyle = () => render`
max-width: 100%;
height: 3rem;
min-height: 3rem;
box-shadow: 0px -4px 10px -2px;
}
form#task-form input {
Expand Down
1 change: 0 additions & 1 deletion src/examples/purity-todo/components/modal-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const modalStyle = (): string => render`
background-color: lightgrey;
font-weight: bold;
position: relative;
box-shadow: 0px 8px 10px -10px;
${lineContainerCSS}
}
Expand Down
19 changes: 19 additions & 0 deletions src/examples/purity-todo/components/task-list-style.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
import {render} from "../../../index.js"
import {isTruthy} from "../../../purity.js"
import {state} from "../app.js"
import {ITEM_DESCRIPTION, TOGGLE_BUTTON} from "./task-item.js"
import type {AppState} from "../app.js"

const isTopScrolled = ({taskListElement}: AppState) =>
taskListElement && taskListElement.scrollTop > 0

const isBottomScrolled = ({taskListElement}: AppState) =>
taskListElement &&
taskListElement.scrollTop <
taskListElement.scrollHeight - taskListElement.clientHeight

export const taskListStyle = (): string => render`
<style id="task-list-style">
ol#task-list {
overflow-y: auto;
flex-grow: 1;
min-height: 3rem;
box-shadow: ${
[
isTopScrolled(state) && "inset 0px 16px 8px -16px",
isBottomScrolled(state) && "inset 0px -16px 8px -16px",
]
.filter(isTruthy)
.join(",") || "none"
};
}
ol#task-list .task-item {
Expand Down
8 changes: 6 additions & 2 deletions src/examples/purity-todo/components/task-list.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {render} from "../../../index.js"
import {state} from "../app.js"
import {setState, state} from "../app.js"
import {resetInput} from "../services/input-form.js"
import {byInput, byStatus, deleteTask, patchTask} from "../services/tasks.js"
import {
Expand All @@ -25,11 +25,15 @@ const handleClick: EventHandler = e => {
// })
}

const handleScroll: EventHandler = ({target}) => {
setState(() => ({taskListElement: target}))
}

export const taskList = (): string => {
const tasks = state.tasks.filter(byInput(state)).filter(byStatus(state))

return render`
<ol id="task-list" ::click=${handleClick}>
<ol id="task-list" ::click=${handleClick} ::scroll=${handleScroll}>
${tasks.map(taskItem)}
</ol>
${taskListStyle()}
Expand Down
2 changes: 1 addition & 1 deletion src/examples/purity-todo/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Purity Todo 2.13",
"name": "Purity Todo 2.14",
"short_name": "ToDo",
"description": "Todo list written with purity.js",
"icons": [
Expand Down
2 changes: 1 addition & 1 deletion src/examples/purity-todo/purity-todo.sw.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const appScope = self.registration.scope

const cacheName = `${appScope}@2.13`
const cacheName = `${appScope}@2.14`
const contentToCache = [
"./",
"./index.html",
Expand Down

0 comments on commit 5854ef0

Please sign in to comment.