Files
pomoday-app/src/composables/useHistory.ts
Paul Spenke 353bbea093 Refactor task components, add mobile-friendly enhancements, and improve settings management
- Introduced `TodoItemTouch`, a responsive task item optimized for mobile interaction with swipe actions.
- Added `MobileActions` for streamlined task creation and settings access on smaller screens.
- Refactored `App.vue` to adapt layouts dynamically for mobile and desktop users.
- Implemented collapsible, categorized task lists with improved handling in `TodoList` and `TodoListTouch`.
- Improved task swipe actions with `useSwipe` for smoother UI interactions.
- Updated styling with DaisyUI theme customization and multi-theme support.
- Enhanced `useSettings` with a `todayShown` toggle for quick agenda visibility.
2026-03-04 10:41:23 +01:00

48 lines
1.3 KiB
TypeScript

import { computed, onMounted, ref } from 'vue'
import { useStore } from './useStore.ts'
const store = ref<string[]>([])
const historyIndex = ref(0)
export default function useHistory() {
const { getValue, setValue } = useStore()
const history = computed<string[]>(() => store.value)
const resetHistoryIndex = () => {
historyIndex.value = store.value.length - 1
}
onMounted(async () => {
store.value = await getValue('history') || []
resetHistoryIndex()
})
const pushHistory = (item: string) => {
if (store.value.length > 20)
store.value.shift()
store.value.push(item.trim())
setValue('history', store.value)
}
const matchHistory = (item: string) => {
const match = store.value.filter(i => i.startsWith(item.trim())).pop()
if (match) {
historyIndex.value = store.value.indexOf(match)
return match
}
return ''
}
const moveHistory = (direction: 'up' | 'down') => {
if (direction === 'up') {
historyIndex.value = Math.max(0, historyIndex.value - 1)
}
else {
historyIndex.value = Math.min(store.value.length - 1, historyIndex.value + 1)
}
}
const historyItem = computed(() => store.value[historyIndex.value])
return { history, pushHistory, matchHistory, moveHistory, historyItem, resetHistoryIndex }
}