Skip to content

Hardcoded CATEGORY_LABELS will drift from database #17

Description

@rioredwards

Location

app.js:7-12

Problem

const CATEGORY_LABELS = {
    1: 'Daily',
    2: 'Error',
    3: 'TDD',
    4: 'Will to go on',
};

Category names are duplicated between the frontend and the database. If a category is added, renamed, or reordered in the DB, the frontend map silently diverges. New categories will fall through to affirmation.category || id || '—' as a fallback, which shows raw IDs to users.

Suggested fix

The app already calls GET /api/v1/categories to check auth. Extend the window.load handler to fetch categories and build the label map dynamically:

const categoriesResult = await fetchCategories();  // add this helper to fetch-utils.js
const CATEGORY_LABELS = Object.fromEntries(
  (categoriesResult.ok ? categoriesResult.data : []).map(c => [c.id, c.type])
);

This eliminates the manual sync requirement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions