Merge pull request #24 from vgcman16/codex/implement-real-feature-flag-handling

Implement feature flag handling
This commit is contained in:
vgcman16 2025-06-05 21:02:30 -05:00 committed by GitHub
commit c775333c44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 83 additions and 22 deletions

View File

@ -1,35 +1,76 @@
export interface Feature {
/**
* Unique identifier for the feature.
*/
id: string;
/**
* Short title of the feature to display in the UI.
*/
name: string;
/**
* Description of what the feature does.
*/
description: string;
/**
* Whether the user has already viewed/acknowledged this feature.
*/
viewed: boolean;
/**
* ISO date string for when the feature was released.
*/
releaseDate: string;
}
export const getFeatureFlags = async (): Promise<Feature[]> => {
/*
* TODO: Implement actual feature flags logic
* This is a mock implementation
const VIEWED_FEATURES_KEY = 'bolt_viewed_features';
// Import client-side localStorage helpers
import { getLocalStorage, setLocalStorage } from '~/lib/persistence';
interface FeatureFromFile {
id: string;
name: string;
description: string;
releaseDate: string;
}
/**
* Fetch the list of available features from the bundled features.json file
* and mark each one as viewed or not based on localStorage state.
*/
return [
{
id: 'feature-1',
name: 'Dark Mode',
description: 'Enable dark mode for better night viewing',
viewed: true,
releaseDate: '2024-03-15',
},
{
id: 'feature-2',
name: 'Tab Management',
description: 'Customize your tab layout',
viewed: false,
releaseDate: '2024-03-20',
},
];
export const getFeatureFlags = async (): Promise<Feature[]> => {
try {
const response = await fetch('/features.json', { cache: 'no-cache' });
if (!response.ok) {
throw new Error(`Failed to fetch features.json: ${response.status}`);
}
const data = (await response.json()) as FeatureFromFile[];
const viewedIds: string[] = getLocalStorage(VIEWED_FEATURES_KEY) || [];
return data.map((feature) => ({
...feature,
viewed: viewedIds.includes(feature.id),
}));
} catch (error) {
console.error('Error loading feature flags:', error);
return [];
}
};
/**
* Persist that a feature has been viewed by the user.
* The viewed state is stored locally in the browser via localStorage.
*/
export const markFeatureViewed = async (featureId: string): Promise<void> => {
/* TODO: Implement actual feature viewed logic */
console.log(`Marking feature ${featureId} as viewed`);
try {
const viewedIds: string[] = getLocalStorage(VIEWED_FEATURES_KEY) || [];
if (!viewedIds.includes(featureId)) {
viewedIds.push(featureId);
setLocalStorage(VIEWED_FEATURES_KEY, viewedIds);
}
} catch (error) {
console.error(`Failed to mark feature ${featureId} as viewed:`, error);
}
};

20
public/features.json Normal file
View File

@ -0,0 +1,20 @@
[
{
"id": "lock-files",
"name": "File Locking",
"description": "Protect important files from accidental changes by locking them",
"releaseDate": "2024-05-01"
},
{
"id": "code-search",
"name": "Code Search",
"description": "Quickly search your project files using the new search bar",
"releaseDate": "2024-05-15"
},
{
"id": "vercel-deploy",
"name": "Vercel Deploy",
"description": "Deploy your project to Vercel directly from the interface",
"releaseDate": "2024-05-22"
}
]