Files
api/web/store/notifications.ts
Michael Datelle 72860e71fe test: create tests for stores batch 3 (#1358)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Added comprehensive test coverage for the purchase, replaceRenew,
modal, notifications, theme, trial, unraidApi, unraidApiSettings,
updateOs, updateOsActions, updateOsChangelog, activationCode, and
callbackActions stores.
- Exposed callback error state in the callbackActions store for external
access.
  - Made error state publicly accessible in the replaceRenew store.

- **Tests**
- Introduced new test files covering state, getters, actions, and side
effects for multiple stores including modal, notifications, purchase,
replaceRenew, theme, trial, unraidApi, unraidApiSettings, updateOs,
updateOsActions, updateOsChangelog, activationCode, and callbackActions.
- Enhanced existing test suites with additional mocks, reactive state
handling, and expanded test cases for improved coverage and robustness.

- **Refactor**
- Improved code clarity and readability in modal, notifications,
purchase, replaceRenew, trial, theme, updateOsActions, callbackActions,
and unraidApi stores through import reorganization and formatting
adjustments.
- Updated imports to include reactive and computed utilities for
enhanced state management in several stores.
- Standardized import styles and streamlined store definitions in the
unraidApiSettings store.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: mdatelle <mike@datelle.net>
2025-04-16 17:06:52 -04:00

33 lines
840 B
TypeScript

import { computed, ref } from 'vue';
import { createPinia, defineStore, setActivePinia } from 'pinia';
import type { NotificationFragmentFragment } from '~/composables/gql/graphql';
setActivePinia(createPinia());
export const useNotificationsStore = defineStore('notifications', () => {
const notifications = ref<NotificationFragmentFragment[]>([]);
const isOpen = ref<boolean>(false);
const title = computed<string>(() =>
isOpen.value ? 'Notifications Are Open' : 'Notifications Are Closed'
);
const toggle = () => (isOpen.value = !isOpen.value);
const setNotifications = (newNotifications: NotificationFragmentFragment[]) => {
notifications.value = newNotifications;
};
return {
// state
isOpen,
// getters
title,
notifications,
// actions
setNotifications,
toggle,
};
});