INTEGRATION.md

5.8 KB · raw

rendered · source

D8 — Feedback HTTP Submission · Integration

Wires the existing FeedbackBody "Send" (currently a local sent flag) to a real HTTP POST, with Sending / Sent / Error(+retry) states.

Files in this draft

Draft file Destination
FeedbackState.kt app/src/main/java/com/peachpasswords/feedback/FeedbackState.kt (new)
FeedbackRepository.kt app/src/main/java/com/peachpasswords/feedback/FeedbackRepository.kt (new)
FeedbackBody.kt replaces the private FeedbackBody in ui/settings/SettingsCardBodies.kt (do NOT add as a separate file)
SettingsViewModel.feedback.snippet.kt additions to ui/settings/SettingsViewModel.kt (do NOT add as a separate file)

New package com.peachpasswords.feedback — create the directory.

Endpoint assumption (mirrors the browser source)

Source of truth: ~/projects/peach-browser/src/background/messages.ts, the SUBMIT_FEEDBACK case (around line 1081) and FEEDBACK_ENDPOINT (line 127).

HTTP client

No new dependency. The project already bundles OkHttp 4.12.0 (app/build.gradle line 100) and uses it in sync/ChirpSyncTransport.kt. FeedbackRepository uses OkHttpClient + Request + RequestBody, and org.json.JSONObject (Android platform, no dep) for the body. The brief mentioned HttpURLConnection as a fallback "unless the project already bundles an HTTP client" — it does, so OkHttp is used.

DI wiring

FeedbackRepository is annotated @Singleton with an @Inject constructor() that takes no arguments, so Hilt constructs it automatically — no @Binds / @Provides module entry is needed (unlike VaultStorage, which needs a @Binds only because it's an interface). Just add it to the VM constructor.

In SettingsViewModel.kt, add the parameter to the existing @Inject constructor:

@HiltViewModel
class SettingsViewModel @Inject constructor(
    private val vault: VaultRepository,
    private val license: LicenseRepository,
    private val feedback: FeedbackRepository,          // ← add
    @ApplicationContext private val appContext: Context,
) : ViewModel() {

Then paste the _feedbackState flow + sendFeedback() + resetFeedback() from SettingsViewModel.feedback.snippet.kt into the class body.

Imports to add to SettingsViewModel.kt

MutableStateFlow, StateFlow, asStateFlow, launch are already imported. Add:

import com.peachpasswords.feedback.FeedbackRepository
import com.peachpasswords.feedback.FeedbackState

Composable wiring (SettingsCardBodies.kt)

  1. Call site — change line 78 from:

            CardId.Feedback -> FeedbackBody(fg)
    

    to:

            CardId.Feedback -> FeedbackBody(fg, vm)
    

    (vm: SettingsViewModel is already a CardBody parameter.)

  2. Body — replace the whole private FeedbackBody(fg: Color) (currently lines 581-623, the block under the Feedback comment banner) with the FeedbackBody(fg: Color, vm: SettingsViewModel) from FeedbackBody.kt. It reuses the file's existing private helpers (SubLabel, Pill, Hint) and does NOT use SubtleButton (it inlines a Send/Retry button so it can carry a disabled state) — SubtleButton is unaffected and still used elsewhere.

Imports to add to SettingsCardBodies.kt

Already present: collectAsState, Row, Alignment, size, LocalContext (unused here). Add:

import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.runtime.DisposableEffect
import com.peachpasswords.feedback.FeedbackState
import com.peachpasswords.ui.theme.LocalPeachAccent

(androidx.compose.foundation.layout.size and ...layout.Row and ...Alignment are already imported.)

State → UI mapping (per brief §7)

State resets to Idle via resetFeedback() in a DisposableEffect when the card leaves composition.

Risks / assumptions