create a helper redo function in this nuxt composable import useInfoSections from…
- User
create a helper redo function in this nuxt composable
import useInfoSections from "~/composables/Tenant/useInfoSections"; import { InfoComponent, InfoSection, InfoSubSection, } from "~/types/Tenant/InfoPages"; import { deepClone } from "~/utils/common/objects"; export default function useActiveBlockHistory() { const { activeBlock, activeComponent, activeSection } = useInfoSections(); const historyStack = useLocalStorage< (InfoSection | InfoSubSection | InfoComponent)[] >("history-stack", [], { deep: true }); let last_snap_shot: InfoSection | InfoSubSection | InfoComponent | null = null; // keeps poping and pushing same value const { pause, resume } = pausableWatch( activeBlock, (prevValue) => { if (prevValue) { if (last_snap_shot) historyStack.value.push(last_snap_shot); last_snap_shot = deepClone(prevValue); } }, { deep: true, }, ); const undoActiveBlock = async () => { const lastBlock = historyStack.value.pop(); if (!lastBlock) return; pause(); await nextTick(); if (lastBlock?.block_type === "component") { activeComponent.value = lastBlock; } else if (lastBlock?.block_type === "section") { activeSection.value = lastBlock; } else if (lastBlock?.block_type === "sub-section") { if (activeSection.value) activeSection.value.sub_sections[lastBlock.id] = lastBlock; } await nextTick(); resume(); }; const clearHistory = () => (historyStack.value = []); onMounted(() => { clearHistory(); }); return { undoActiveBlock, clearHistory }; } ``
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.