Skip to content

Refactor: Extract hardcoded placeholder URLs to constants #138

@quiet-node

Description

@quiet-node

Problem Statement

Two settings tabs have hardcoded URL strings used as input placeholder text:

  • src/settings/tabs/ModelTab.tsx"http://127.0.0.1:11434" (the default Ollama endpoint)
  • src/settings/tabs/SearchTab.tsx"http://127.0.0.1:25017" and "http://127.0.0.1:25018" (search sandbox endpoints)

These same URL strings also appear in documentation and other parts of the codebase. If the default ports ever change, or if we want to reuse these values elsewhere, having them as named constants makes that easy. Right now they are scattered inline strings.


Proposed Solution

Move the hardcoded URL strings into a shared constants file and reference them by name.

Steps

  1. Create (or extend) a constants file

    A good location is src/config/constants.ts. If the file does not exist yet, create it.

    Define the constants there:

    export const DEFAULT_OLLAMA_URL = 'http://127.0.0.1:11434';
    export const DEFAULT_SEARCH_URL_PRIMARY = 'http://127.0.0.1:25017';
    export const DEFAULT_SEARCH_URL_SECONDARY = 'http://127.0.0.1:25018';

    Choose names that make the purpose clear. The names above are suggestions.

  2. Update ModelTab.tsx

    Import the constant and replace the inline string in the placeholder prop.

  3. Update SearchTab.tsx

    Same: import and replace both inline URL strings.

  4. Check for other occurrences

    Run a quick search for 11434, 25017, and 25018 in src/ to see if these values appear anywhere else. If so, replace those too.


Definition of Done

  • A constants file exists (new or extended) with named exports for the three URLs
  • ModelTab.tsx uses the constant instead of the inline string
  • SearchTab.tsx uses the constants instead of the inline strings
  • No other occurrences of the raw port numbers remain as magic strings in src/
  • bun run test:all:coverage passes (100% coverage maintained)
  • bun run validate-build passes with zero warnings and zero errors

Getting Started

  1. Open src/settings/tabs/ModelTab.tsx and search for 11434
  2. Open src/settings/tabs/SearchTab.tsx and search for 25017 and 25018
  3. Create src/config/constants.ts with the named exports
  4. Replace the inline strings and import the constants
  5. Run bun run validate-build to confirm nothing is broken

This is a pure refactor: no behavior changes, no new features. It is a great way to get familiar with the codebase structure before tackling something bigger.

Questions? Leave a comment on this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions