diff --git a/components/demo/Journey/index.tsx b/components/demo/Journey/index.tsx index 19302e1..11e97b9 100644 --- a/components/demo/Journey/index.tsx +++ b/components/demo/Journey/index.tsx @@ -74,7 +74,7 @@ export function useStarshipYPosition( const todoDistanceFromCommonAncestor = nextTodoPosition.top const starshipHeightAdjustment = (nextTodoPosition.height - starship?.offsetHeight) / 2 - const additionalOffset = 0 // Just a visual thing to make the center of the rocket align and ignore the tail + const additionalOffset = 32 // Hack to accommodate the 'load more' buttons, should calculate properly based on common ancestor. const y = todoDistanceFromCommonAncestor + diff --git a/components/pages/Home.tsx b/components/pages/Home.tsx index 160e865..cbfc3cd 100644 --- a/components/pages/Home.tsx +++ b/components/pages/Home.tsx @@ -2,7 +2,6 @@ import { menuController } from '@ionic/core/components' import { IonButton, IonButtons, - IonCheckbox, IonCol, IonContent, IonFab, @@ -11,11 +10,8 @@ import { IonGrid, IonHeader, IonIcon, - IonInfiniteScroll, - IonInfiniteScrollContent, IonInput, IonItem, - IonLabel, IonList, IonMenu, IonMenuButton, @@ -35,7 +31,10 @@ import { import { useLiveQuery } from 'dexie-react-hooks' import { add, - documentText, + chevronDownOutline, + chevronUpCircleOutline, + chevronUpCircleSharp, + chevronUpOutline, filterSharp, locateOutline, rocketSharp, @@ -57,12 +56,11 @@ import { useStarshipYPosition } from '../demo/Journey' import Tracjectory from '../landingPage/Journey/Trajectory' import NoteProviders from '../notes/providers' import useSettings from '../settings/useSettings' -import { getIonIcon } from '../starRoles/icons' +import { TodoCard, TodoListItem } from '../todos' import { useTodoActionSheet } from '../todos/TodoActionSheet' import useTodoContext, { TodoContextProvider } from '../todos/TodoContext' import { useCreateTodoModal } from '../todos/create/useCreateTodoModal' import useView, { ViewProvider } from '../view' -import { TodoCard, TodoListItem } from '../todos' const Home = () => { useGlobalKeyboardShortcuts() @@ -112,17 +110,6 @@ export default Home export const TodoLists = ({}: {}) => { // Initial loading & scrolling stuff const contentRef = useRef(null) - const [enablePagination, setEnablePagination] = useState(false) - // useEffect(() => { - // setTimeout(() => { - // // TODO: See if ionViewDidEnter works better than setTimeout - // console.debug('Scrolling to bottom', contentRef.current) - // contentRef.current?.scrollToBottom(500) - // setTimeout(() => { - // setEnablePagination(true) - // }, 500) - // }, 200) - // }, []) // Query stuff const [logLimit, setLogLimit] = useState(7) @@ -143,26 +130,6 @@ export const TodoLists = ({}: {}) => { }) }, [fab, focusedStarRole, presentCreateTodoModal]) - // Keyboard shortcut stuff - useEffect(() => { - const handleKeyDown = (event: KeyboardEvent) => { - if (event.target !== document.body) return - - if (event.key === 'c') { - event.preventDefault() - openCreateTodoModal() - if (fab.current) fab.current.activated = true - } else if (event.key === 's') { - event.preventDefault() - contentRef.current?.scrollToBottom(500) - } - } - document.addEventListener('keydown', handleKeyDown) - return () => { - document.removeEventListener('keydown', handleKeyDown) - } - }, [contentRef, fab, openCreateTodoModal]) - const { inActiveStarRoles, query } = useView() const todos = useLiveQuery(async () => { @@ -217,17 +184,6 @@ export const TodoLists = ({}: {}) => { }, [inActiveStarRoles, iceboxLimit, logLimit, query]) const loading = todos === undefined - - const starRoles = useLiveQuery(() => db.starRoles.toArray()) - - const [debug, setDebug] = useState('') - useEffect(() => { - const params = new URLSearchParams(window.location.search) - const searchQuery = params.get('debug') - if (searchQuery) { - setDebug(searchQuery) - } - }, []) const todosCount = useMemo( () => todos === undefined @@ -236,12 +192,14 @@ export const TodoLists = ({}: {}) => { [todos], ) + const starRoles = useLiveQuery(() => db.starRoles.toArray()) + // Its possible for ref not to change when todo is completed because one other than 'next' is completed in which case starship doesn't move // Consider using a callback ref instead: https://stackoverflow.com/questions/60881446/receive-dimensions-of-element-via-getboundingclientrect-in-react const nextTodoRef = useRef(null) const { nextTodo: { - position: [_, setNextTodoPosition], + position: [nextTodoPosition, setNextTodoPosition], }, } = useTodoContext() // TODO: When dev tools aren't open the todo has zero height @@ -268,10 +226,34 @@ export const TodoLists = ({}: {}) => { }, 1) }, [nextTodoRef, setNextTodoPosition, todos]) // The todos dep is used as an imperfect proxy for one the position of the next todo changes + // Keyboard shortcut stuff + useEffect(() => { + const handleKeyDown = (event: KeyboardEvent) => { + if (event.target !== document.body) return + + if (event.key === 'c') { + event.preventDefault() + openCreateTodoModal() + if (fab.current) fab.current.activated = true + } else if (event.key === 's') { + event.preventDefault() + const y = nextTodoPosition ? nextTodoPosition.top + 32 : 0 + contentRef.current?.scrollToPoint(undefined, y, 500) + } + } + document.addEventListener('keydown', handleKeyDown) + return () => { + document.removeEventListener('keydown', handleKeyDown) + } + }, [contentRef, fab, nextTodoPosition, openCreateTodoModal]) + const [present] = useTodoActionSheet() return ( - + { ) : ( <> - { - setLogLimit(limit => limit + 10) - setTimeout(() => event.target.complete(), 500) - }} + setLogLimit(limit => limit + 10)} + size="small" > - - + + { - { - setIceboxLimit(limit => limit + 10) - setTimeout(() => event.target.complete(), 500) - }} + setIceboxLimit(limit => limit + 10)} + size="small" > - - + + )} @@ -774,7 +759,7 @@ export const Journey = ({ const [starshipY] = useStarshipYPosition( starship?.current, nextTodoPosition, - commonAncestor?.current, + commonAncestor.current, ) return (