-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Different approach for positioning the dialog
- Loading branch information
Showing
15 changed files
with
126 additions
and
50 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
6 changes: 6 additions & 0 deletions
6
...ts/budgetkey/src/app/list-components/add-to-list-dialog/add-to-list-dialog.component.less
This file contains 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 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 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 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 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 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 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
57 changes: 57 additions & 0 deletions
57
projects/budgetkey/src/app/list-components/list-dialog.service.ts
This file contains 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,57 @@ | ||
import { Injectable, signal } from '@angular/core'; | ||
import { DocResultEntry } from '../common-components/search-models'; | ||
import { ListContents } from '../common-components/services/lists.service'; | ||
import { Subject, Subscription, animationFrameScheduler, interval, takeUntil, timer } from 'rxjs'; | ||
|
||
export interface AddToListDialogCommand { | ||
command: 'add-item' | 'remove-item' | 'open-list' | 'new-list'; | ||
list?: ListContents; | ||
itemNotes?: string; | ||
itemId?: number; | ||
listTitle?: string; | ||
}; | ||
|
||
@Injectable() | ||
export class ListDialogService { | ||
|
||
dialogOpen = signal(false); | ||
listSelection = signal(false); | ||
doc: any = signal<DocResultEntry|null>(null); | ||
top = signal(0); | ||
right = signal(0); | ||
|
||
executeQ = new Subject<[DocResultEntry, AddToListDialogCommand[]]>(); | ||
closeQ = new Subject<void>(); | ||
positionSub: Subscription | null = null; | ||
|
||
constructor() { } | ||
|
||
execute(commands: AddToListDialogCommand[]) { | ||
this.executeQ.next([this.doc(), commands]); | ||
} | ||
|
||
open(doc: DocResultEntry, listSelection: boolean, el: HTMLElement) { | ||
if (this.dialogOpen()) { | ||
this.close(); | ||
timer(0).subscribe(() => this.open(doc, listSelection, el)); | ||
} else { | ||
this.doc.set(doc); | ||
this.listSelection.set(listSelection); | ||
this.positionSub = interval(16, animationFrameScheduler).pipe( | ||
takeUntil(this.closeQ), | ||
).subscribe(() => { | ||
const rect = el.getBoundingClientRect(); | ||
this.top.set(rect.bottom); | ||
this.right.set(rect.right); | ||
}); | ||
this.dialogOpen.set(true); | ||
} | ||
} | ||
|
||
close() { | ||
console.log('closed'); | ||
this.positionSub?.unsubscribe(); | ||
this.positionSub = null; | ||
this.closeQ.next(); | ||
} | ||
} |
This file contains 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 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
Oops, something went wrong.