Appearance
Stores Documentation ​
Overview ​
This section documents all Pinia stores used in the Collage Brand Portal. Stores are located in app/stores/ and use Pinia for state management.
Store Structure ​
stores/
├── auth.ts # Authentication store
├── appData.ts # Application data store
├── search.ts # Search store
├── download.ts # Download store
├── analytics.ts # Analytics store
└── index.ts # Store exportsStore Documentation ​
Core Stores ​
- Auth Store - Authentication state management with HTTP-only cookie support
- App Data Store - Application data management with caching support
- Search Store - Search state management
Feature Stores ​
- Download Store - Download state management with progress tracking
- Analytics Store - Analytics and insights tracking state
Store Modules ​
Auth Store (auth.ts) ​
Centralized authentication state management with HTTP-only cookie support.
State:
typescript
{
user: User | null // Current user data
accessToken: string | null // JWT access token
loading: boolean // Loading state
isAuthenticated: boolean // Computed authentication status
}Actions:
login(email, password, workspaceId)- User loginlogout()- User logoutgetUser()- Fetch current user dataloginWithToken(token, url)- Token-based loginstoreSession(token, userData)- Store session in cookiesclearSession()- Clear session
Getters:
isAuthenticated- Computed authentication statuscurrentWorkspace- Current workspace data
Documentation: Auth Store
File Path: app/stores/auth.ts
App Data Store (appData.ts) ​
Application data management with caching support.
State:
typescript
{
bannerData: Banner[] // Banner carousel data
tileData: Tile[] // Dashboard tiles
dashboardData: DashboardData // Dashboard metrics
folders: Folder[] // Folder list
leftMenuOpen: boolean // Sidebar state
logo: string // Brand logo
brand: Brand | null // Brand data
subscriptionFeatures: object // Subscription features
}Actions:
fetchDashboardData(options?)- Fetch dashboard data (cached)fetchBannerData(options?)- Fetch banners (cached)fetchTileData(options?)- Fetch tiles (cached)fetchFolders(subfolderList, options?)- Fetch folders (cached)fetchBrandData()- Fetch brand datasetLeftMenuOpen(value)- Toggle sidebar
Caching:
- Default TTL: 15 minutes
- Cache can be bypassed with
force: true - Custom TTL can be set with
ttlMsoption
Documentation: App Data Store
File Path: app/stores/appData.ts
Search Store (search.ts) ​
Search state management with Typesense integration.
State:
typescript
{
query: string // Search query
filters: SearchFilters // Active filters
results: SearchResult[] // Search results
loading: boolean // Loading state
pagination: Pagination // Pagination data
}Actions:
setQuery(query)- Set search querysetFilters(filters)- Set search filterssearch(query, filters)- Perform searchclearSearch()- Clear search stateloadMore()- Load more results
Documentation: Search Store
File Path: app/stores/search.ts
Download Store (download.ts) ​
Download state management with progress tracking and multiple download methods.
State:
typescript
{
pinned: boolean, // Download panel pinned state
expanded: boolean, // Download panel expanded state
count: number, // Number of active downloads
files: Record<string, DownloadItem> // Active download items
}Actions:
downloadFile(payload)- Download single file with progressdownloadMultipleFiles(payload)- Download multiple files as ZIPdownloadImageAsset(payload)- Download image asset with proper MIME typesetDownloadingItem(id, item)- Update download item state
Features:
- Progress tracking
- Cancellation support
- Stream-based downloads for large files
- Email notification for very large downloads
Documentation: Download Store
File Path: app/stores/download.ts
Analytics Store (analytics.ts) ​
Analytics and insights tracking state.
State:
typescript
{
InsightsTransaction: Record<string, any>, // Transaction insights
InsightsTransactionShare: Record<string, any>, // Share transaction insights
userAgentAndLocation: Record<string, any> // User agent and location
}Actions:
setUserAgentAndLocation(payload)- Set user agent and location data
Getters:
getInsightsTransaction- Get transaction insightsgetInsightsTransactionShare- Get share transaction insightsgetUserAgentAndLocation- Get user agent and location
Documentation: Analytics Store
File Path: app/stores/analytics.ts
Store Patterns ​
Basic Store Structure ​
typescript
import { defineStore } from 'pinia'
import type { MyStoreState } from '~/types'
export const useMyStore = defineStore('myStore', () => {
// State
const data = ref<MyData[]>([])
const loading = ref(false)
const error = ref(null)
// Getters
const hasData = computed(() => data.value.length > 0)
// Actions
const fetchData = async () => {
loading.value = true
try {
const result = await api.getData()
data.value = result
} catch (e) {
error.value = e
} finally {
loading.value = false
}
}
return {
// State
data,
loading,
error,
// Getters
hasData,
// Actions
fetchData
}
})Store with Caching ​
typescript
export const useMyStore = defineStore('myStore', () => {
const data = ref(null)
const lastFetched = ref<number | null>(null)
const CACHE_TTL_MS = 15 * 60 * 1000 // 15 minutes
const isCacheValid = () => {
if (!lastFetched.value) return false
return Date.now() - lastFetched.value < CACHE_TTL_MS
}
const fetchData = async (options: { force?: boolean } = {}) => {
const { force = false } = options
if (!force && data.value && isCacheValid()) {
return data.value
}
const result = await api.getData()
data.value = result
lastFetched.value = Date.now()
return result
}
return { data, fetchData }
})Best Practices ​
- Single Responsibility: Each store should manage a specific domain
- Type Safety: Use TypeScript types from
~/types - Actions for Async: Use actions for all async operations
- Getters for Computed: Use getters for computed values
- Error Handling: Implement consistent error handling
- Loading States: Provide loading state management
- Caching: Implement caching for frequently accessed data
- Persistence: Use persistence plugin for important state
- Naming: Use descriptive store and action names
- Documentation: Document state, getters, and actions