Repository navigation
feat(pairing): device pairing dialog, nearby pairing and pairing API #342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Joshua-Wang223
wants to merge
1
commit into
tonyantony300:main
Choose a base branch
from
Joshua-Wang223:feat/device-pairing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| import { useEffect, useRef, useState } from 'react' | ||
|
|
||
| import { useTranslation } from '@/i18n' | ||
| import { Button } from '../ui/button' | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogFooter, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| } from '../ui/dialog' | ||
| import { useReceiverContext } from './ReceiverProvider' | ||
|
|
||
| /** | ||
| * Global post-transfer pairing prompt. | ||
| * | ||
| * Lives above the routed screens (inside `ReceiverProvider`) so a prompt that | ||
| * arrives while the user is on Settings or Devices is not lost. Pairing is | ||
| * asynchronous: this dialog only disables itself while the request is being | ||
| * delivered; the actual result arrives as `device-paired`. | ||
| */ | ||
| export function PairPromptDialog() { | ||
| const { t } = useTranslation() | ||
| const { pairPrompt, acceptPairPrompt, dismissPairPrompt } = | ||
|
Check failure on line 25 in frontend/src/components/receiver/PairPromptDialog.tsx
|
||
| useReceiverContext() | ||
| const [submitting, setSubmitting] = useState(false) | ||
| const [error, setError] = useState<string | null>(null) | ||
| /** Suppresses the controlled Dialog's close event after a programmatic close. */ | ||
| const handledRef = useRef(false) | ||
|
|
||
| // A new sender (or a retry after dismissal) starts clean. | ||
| useEffect(() => { | ||
| if (!pairPrompt) return | ||
| handledRef.current = false | ||
| setError(null) | ||
| setSubmitting(false) | ||
| }, [pairPrompt]) | ||
|
|
||
| if (!pairPrompt) return null | ||
|
|
||
| const accept = async () => { | ||
| // `acceptPairPrompt` clears the prompt on success; mark this as a | ||
| // programmatic close so onOpenChange does not record a dismissal. | ||
| handledRef.current = true | ||
| setSubmitting(true) | ||
| setError(null) | ||
| try { | ||
| // The hook keeps the prompt open when the request cannot be | ||
| // delivered, so the user can retry. | ||
| const sent = await acceptPairPrompt() | ||
| if (!sent) { | ||
| handledRef.current = false | ||
| setError(t('common:receiver.pairFailed')) | ||
| } | ||
| } finally { | ||
| setSubmitting(false) | ||
| } | ||
| } | ||
|
|
||
| const dismiss = () => { | ||
| handledRef.current = true | ||
| dismissPairPrompt() | ||
| } | ||
|
|
||
| return ( | ||
| <Dialog | ||
| open | ||
| onOpenChange={(open) => { | ||
| if (!open && !submitting && !handledRef.current) dismiss() | ||
| }} | ||
| > | ||
| <DialogContent> | ||
| <DialogHeader> | ||
| <DialogTitle>{t('common:receiver.pairPromptTitle')}</DialogTitle> | ||
| <DialogDescription> | ||
| {t('common:receiver.pairPromptDescription', { | ||
| name: pairPrompt.displayName, | ||
| })} | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
| {error ? ( | ||
| <p className="text-sm text-destructive" role="alert"> | ||
| {error} | ||
| </p> | ||
| ) : null} | ||
| <DialogFooter> | ||
| <Button | ||
| variant="outline" | ||
| size="sm" | ||
| onClick={dismiss} | ||
| disabled={submitting} | ||
| > | ||
| {t('common:receiver.pairPromptDecline')} | ||
| </Button> | ||
| <Button size="sm" onClick={accept} disabled={submitting}> | ||
| {t('common:receiver.pairPromptAccept')} | ||
| </Button> | ||
| </DialogFooter> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: tonyantony300/dashbeam
Length of output: 1898
Script executed:
Repository: tonyantony300/dashbeam
Length of output: 4666
Add the pairing prompt members to
UseReceiverReturn.PairPromptDialogreadspairPrompt,acceptPairPrompt, anddismissPairPromptfromuseReceiverContext(). That context is typed asUseReceiverReturn, which does not declare these members. The TypeScript check fails with TS2339, so the PR cannot pass typecheck.No definition of these three members exists in
frontend/src. The hook and provider need to expose prompt state and both handlers, with the return type updated to match.GitHub Actions: Lint & Format CI / 0_Lint & format.txt
[error] 25-25: TypeScript (tsc, run via
pnpm run lint) error TS2339:pairPrompt,acceptPairPrompt, anddismissPairPromptdo not exist on typeUseReceiverReturn.GitHub Actions: Lint & Format CI / Lint & format
[error] 25-25: TypeScript error TS2339:
UseReceiverReturndoes not containpairPrompt,acceptPairPrompt, ordismissPairPrompt.pnpm run lintfailed duringtsc --noEmit --skipLibCheck.GitHub Check: Lint & format
[failure] 25-25:
Property 'dismissPairPrompt' does not exist on type 'UseReceiverReturn'.
[failure] 25-25:
Property 'acceptPairPrompt' does not exist on type 'UseReceiverReturn'.
[failure] 25-25:
Property 'pairPrompt' does not exist on type 'UseReceiverReturn'.