tududi/frontend/utils/featureFlags.ts
Chris 269197e3db
Feat: habits (#707)
* Scaffold habits

* Fix today issues

* Fix buttons in taskitem

* Fix mobile layout

* Fix creation process

* Add to sidebar

* fixup! Add to sidebar

* fixup! fixup! Add to sidebar
2025-12-13 08:47:52 +02:00

53 lines
1.3 KiB
TypeScript

import { getApiPath } from '../config/paths';
export interface FeatureFlags {
backups: boolean;
calendar: boolean;
habits: boolean;
}
let cachedFeatureFlags: FeatureFlags | null = null;
export const getFeatureFlags = async (): Promise<FeatureFlags> => {
if (cachedFeatureFlags) {
return cachedFeatureFlags;
}
try {
const response = await fetch(getApiPath('feature-flags'), {
credentials: 'include',
});
if (!response.ok) {
console.error('Failed to fetch feature flags');
return {
backups: false,
calendar: false,
habits: false,
};
}
const data = await response.json();
const defaultFlags: FeatureFlags = {
backups: false,
calendar: false,
habits: false,
};
cachedFeatureFlags = {
...defaultFlags,
...data.featureFlags,
};
return cachedFeatureFlags;
} catch (error) {
console.error('Error fetching feature flags:', error);
return {
backups: false,
calendar: false,
habits: false,
};
}
};
export const clearFeatureFlagsCache = () => {
cachedFeatureFlags = null;
};