Draft: Resolve "Edit card query option in card context menu"

This commit is contained in:
Jason Wall 2024-07-08 12:07:22 +00:00
parent 9af7e31a70
commit 0a9a147220
8 changed files with 113 additions and 7 deletions

View File

@ -41,6 +41,7 @@ import { MarkedOptions, MarkedRenderer } from 'ngx-markdown';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module'; import { AppRoutingModule } from './app-routing.module';
import { AddToPageModalComponent } from './components/add-to-page-modal/add-to-page-modal.component'; import { AddToPageModalComponent } from './components/add-to-page-modal/add-to-page-modal.component';
import { CardEditModalComponent } from './components/card-edit-modal/card-edit-modal.component';
import { HelpModalComponent } from './components/help-modal/help-modal.component'; import { HelpModalComponent } from './components/help-modal/help-modal.component';
import { NoteEditModalComponent } from './components/note/edit-modal/note-edit-modal.component'; import { NoteEditModalComponent } from './components/note/edit-modal/note-edit-modal.component';
import { NoteCardComponent } from './components/note/note-card.component'; import { NoteCardComponent } from './components/note/note-card.component';
@ -95,6 +96,7 @@ export function markedOptionsFactory(): MarkedOptions {
VersePickerModalComponent, VersePickerModalComponent,
SettingsComponent, SettingsComponent,
OkCancelModalComponent, OkCancelModalComponent,
CardEditModalComponent,
], ],
imports: [ imports: [
BrowserModule, BrowserModule,

View File

@ -0,0 +1,16 @@
<mat-toolbar>
<mat-icon>save</mat-icon>
</mat-toolbar>
<mat-dialog-content class="content">
<form [formGroup]="form">
<mat-form-field class="page-title">
<mat-label>Query</mat-label>
<input formControlName="qry" matInput />
</mat-form-field>
</form>
<div mat-dialog-actions>
<button mat-button (click)="save()">Save</button>
<button mat-button (click)="cancel()">Cancel</button>
</div>
</mat-dialog-content>

View File

@ -0,0 +1,25 @@
.close-button {
float: right;
}
.title {
width: 100%;
padding-left: 1rem;
font-size: 1.5rem;
overflow: hidden;
}
.mat-mdc-form-field {
display: block;
}
.page-title {
min-width: 50vw;
padding-top: 12px;
}
.mat-mdc-dialog-content {
min-width: 60vw;
min-height: 20vh;
max-height: 80vh;
}

View File

@ -0,0 +1,45 @@
import { Component, Inject } from '@angular/core';
import { FormGroup, UntypedFormBuilder } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { CardItem } from 'src/app/models/card-state';
import { AppService } from 'src/app/services/app.service';
@Component({
selector: 'app-card-edit-modal',
templateUrl: 'card-edit-modal.component.html',
styleUrls: ['./card-edit-modal.component.scss'],
})
export class CardEditModalComponent {
form: FormGroup;
dialogTitle = 'Save Page using Current Cards';
oldCard: CardItem;
constructor(
@Inject(MAT_DIALOG_DATA) public data: CardEditModalData,
public dialogRef: MatDialogRef<CardEditModalComponent>,
private appService: AppService,
private fb: UntypedFormBuilder
) {
this.oldCard = data.card;
this.form = this.fb.group(data.card);
}
cancel() {
this.dialogRef.close();
}
save() {
this.appService.updateCard(
{
qry: this.form.get('qry').value,
type: this.form.get('type').value,
} as CardItem,
this.oldCard
);
this.dialogRef.close();
}
}
export interface CardEditModalData {
card: CardItem;
}

View File

@ -1,5 +1,5 @@
import { Clipboard } from '@angular/cdk/clipboard'; import { Clipboard } from '@angular/cdk/clipboard';
import { Component,ElementRef, EventEmitter, Input, Output } from '@angular/core'; import { Component, ElementRef, EventEmitter, Input, Output } from '@angular/core';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
@ -8,6 +8,7 @@ import { SubscriberBase } from '../common/subscriber-base';
import { AddToPageModalComponent } from '../components/add-to-page-modal/add-to-page-modal.component'; import { AddToPageModalComponent } from '../components/add-to-page-modal/add-to-page-modal.component';
import { CardItem } from '../models/card-state'; import { CardItem } from '../models/card-state';
import { AppService } from '../services/app.service'; import { AppService } from '../services/app.service';
import { CardEditModalComponent } from './card-edit-modal/card-edit-modal.component';
@Component({ @Component({
template: '', template: '',
@ -83,4 +84,12 @@ export class CardComponent extends SubscriberBase {
moveCardUp() { moveCardUp() {
this.appService.moveCard(this.cardItem, MoveDirection.Up); this.appService.moveCard(this.cardItem, MoveDirection.Up);
} }
editReferenceModal() {
this.dialog.open(CardEditModalComponent, {
data: {
card: { ...this.cardItem } as CardItem,
},
});
}
} }

View File

@ -14,21 +14,21 @@ export class PageEditModalComponent {
dialogTitle = 'Save Page using Current Cards'; dialogTitle = 'Save Page using Current Cards';
constructor( constructor(
@Inject(MAT_DIALOG_DATA) public title: PageEditModalData, @Inject(MAT_DIALOG_DATA) public data: PageEditModalData,
public dialogRef: MatDialogRef<PageEditModalComponent>, public dialogRef: MatDialogRef<PageEditModalComponent>,
private appService: AppService, private appService: AppService,
private fb: UntypedFormBuilder private fb: UntypedFormBuilder
) { ) {
if (title) { if (data) {
this.dialogTitle = 'Edit Page Name'; this.dialogTitle = 'Edit Page Name';
} else { } else {
title = { data = {
title: '', title: '',
savedPage: null, savedPage: null,
}; };
} }
this.form = this.fb.group(title); this.form = this.fb.group(data);
} }
cancel() { cancel() {
@ -38,7 +38,7 @@ export class PageEditModalComponent {
save() { save() {
if (this.dialogTitle === 'Edit Page Name') { if (this.dialogTitle === 'Edit Page Name') {
this.appService.updateSavedPage({ this.appService.updateSavedPage({
...this.title.savedPage, ...this.data.savedPage,
title: this.form.get('title').value, title: this.form.get('title').value,
}); });
} else { } else {

View File

@ -102,6 +102,10 @@
<mat-icon>more_vert</mat-icon> <mat-icon>more_vert</mat-icon>
</button> </button>
<mat-menu #moreMenu="matMenu"> <mat-menu #moreMenu="matMenu">
<button mat-menu-item (click)="editReferenceModal()">
<mat-icon>edit</mat-icon>
<span>Edit Reference</span>
</button>
<button mat-menu-item (click)="copy()"> <button mat-menu-item (click)="copy()">
<mat-icon>content_copy</mat-icon> <mat-icon>content_copy</mat-icon>
<span>Copy Passage</span> <span>Copy Passage</span>

View File

@ -294,7 +294,7 @@ export const updateCardAction = (newCard: CardItem, oldCard: CardItem): AppActio
...state, ...state,
currentCards: new Storable( currentCards: new Storable(
state.currentCards.value.map((c) => { state.currentCards.value.map((c) => {
if (c === oldCard) { if (c.type === oldCard.type && c.qry === oldCard.qry) {
return newCard; return newCard;
} }
return c; return c;
@ -824,6 +824,11 @@ export class AppService extends createReducingService(initialState) {
); );
} }
async updateCard(newCard: CardItem, oldCard: CardItem) {
const card = await this.getCardByQuery(newCard.qry.trim());
this.dispatch(updateCardAction(card, oldCard));
}
async clearCards() { async clearCards() {
this.dispatch(clearCardsAction()); this.dispatch(clearCardsAction());
} }