This repository has been archived on 2026-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
gitgram-ai/gitgram/mobile/store/settingsStore.ts
caelum0x 46bf9b83bf feat: round-5 external harvest (22 features ported from external/ into 5 products)
Harvest valuable features from external/ reference repos, adapted to each
product's stack and wired in; all products typecheck clean.

- gitgram-web (5): clickable @mention/#hashtag linkify in rendered content
  (munia), + feed/notification/accessibility patterns; install @testing-library/dom
- gitgram-backend (3): feed thread dedup + muted-thread removal (bluesky),
  GitHub star/follow write-back via OAuth (gh-social)
- gitgram-mobile (4): double-tap-to-like + heart bounce (proximity), haptics layer
  (bluesky useHaptics), + gesture/feed UX
- aitm-api (4): beads ready/dependency-DAG endpoints + atomic claim (beads)
- aitm-mcp (6): beads_ready work-queue tool, context-efficient projections,
  transport arg aliasing (context7/pal-mcp/beads)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-28 18:48:46 +03:00

65 lines
2.0 KiB
TypeScript

import { create } from 'zustand';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { logger } from '../utils/logger';
const HAPTICS_DISABLED_KEY = 'settings:hapticsDisabled';
const ALT_TEXT_REQUIRED_KEY = 'settings:altTextRequired';
interface SettingsState {
// Whether tactile haptic feedback is disabled across the app.
hapticsDisabled: boolean;
// Whether the composer requires alt text on every image before posting.
altTextRequired: boolean;
// True once persisted preferences have been read from storage.
hydrated: boolean;
hydrate: () => Promise<void>;
setHapticsDisabled: (disabled: boolean) => Promise<void>;
setAltTextRequired: (required: boolean) => Promise<void>;
}
/**
* Lightweight, app-wide user preferences persisted to AsyncStorage. Kept
* separate from authStore so settings survive logout and stay focused.
*/
export const useSettingsStore = create<SettingsState>((set) => ({
hapticsDisabled: false,
altTextRequired: false,
hydrated: false,
hydrate: async () => {
try {
const [hapticsValue, altTextValue] = await Promise.all([
AsyncStorage.getItem(HAPTICS_DISABLED_KEY),
AsyncStorage.getItem(ALT_TEXT_REQUIRED_KEY),
]);
set({
hapticsDisabled: hapticsValue === 'true',
altTextRequired: altTextValue === 'true',
hydrated: true,
});
} catch (error) {
logger.error('Failed to hydrate settings:', error);
set({ hydrated: true });
}
},
setHapticsDisabled: async (disabled: boolean) => {
set({ hapticsDisabled: disabled });
try {
await AsyncStorage.setItem(HAPTICS_DISABLED_KEY, disabled ? 'true' : 'false');
} catch (error) {
logger.error('Failed to persist hapticsDisabled:', error);
}
},
setAltTextRequired: async (required: boolean) => {
set({ altTextRequired: required });
try {
await AsyncStorage.setItem(ALT_TEXT_REQUIRED_KEY, required ? 'true' : 'false');
} catch (error) {
logger.error('Failed to persist altTextRequired:', error);
}
},
}));