Files
oil-formula-calculator/frontend/src/stores/ui.js
Hera Zhao 96504ed1d7
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 4s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 13s
Test / e2e-test (push) Failing after 1m4s
Resume pending action after login (favorite, diary, QR upload)
Add pendingAction callback to UI store. When user clicks favorite,
save-to-diary, or upload QR while not logged in, the action is stored
and automatically executed after successful login/register instead of
reloading the page.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 22:39:59 +00:00

55 lines
1.1 KiB
JavaScript

import { defineStore } from 'pinia'
import { ref } from 'vue'
export const useUiStore = defineStore('ui', () => {
const currentSection = ref('search')
const showLoginModal = ref(false)
const toasts = ref([])
const pendingAction = ref(null)
let toastId = 0
function showSection(name) {
currentSection.value = name
}
function showToast(msg, duration = 1800) {
const id = ++toastId
toasts.value.push({ id, msg })
setTimeout(() => {
toasts.value = toasts.value.filter((t) => t.id !== id)
}, duration)
}
function openLogin(afterLogin) {
if (afterLogin) {
pendingAction.value = afterLogin
}
showLoginModal.value = true
}
function closeLogin() {
showLoginModal.value = false
}
function runPendingAction() {
if (pendingAction.value) {
const action = pendingAction.value
pendingAction.value = null
action()
}
}
return {
currentSection,
showLoginModal,
toasts,
pendingAction,
showSection,
showToast,
openLogin,
closeLogin,
runPendingAction,
}
})