Skip to content

Commit

Permalink
Adds copy button to copy vote data
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkar598 committed Aug 27, 2023
1 parent bff4977 commit 6068a73
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/app/vote-data/vote-data.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
icon="fa-regular fa-paste"
styleClass="mr-5"
></p-button>
<p-button
[label]="this.copied ? 'Copied!' : 'Copy'"
(onClick)="copy()"
aria-describedby="vote-data-help"
icon="fa-solid fa-copy"
styleClass="mr-5"
></p-button>
<p-button
label="Clear"
(onClick)="voteService.clear()"
Expand Down
21 changes: 17 additions & 4 deletions src/app/vote-data/vote-data.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, HostListener } from "@angular/core";
import { map } from "rxjs";
import { SettingsService } from "../settings.service";
import { ValidatedBallot } from "../types";
import { VoteService } from "../vote.service";

Expand All @@ -12,6 +13,7 @@ export class VoteDataComponent {
listening = false;
displayHelp = false;
pasteInvalid = false;
copied = false;

errorData$ = this.voteService.preprocessingData$.pipe(
map(data => {
Expand All @@ -36,7 +38,10 @@ export class VoteDataComponent {
map(x => x?.ballots.filter(x => x.parseError !== undefined).length),
);

constructor(public voteService: VoteService) {}
constructor(
public voteService: VoteService,
public settingService: SettingsService,
) {}

@HostListener("document:paste", ["$event"])
paste(event: ClipboardEvent) {
Expand All @@ -51,8 +56,16 @@ export class VoteDataComponent {
event.clipboardData.getData("text"),
);

setTimeout(() => {
this.pasteInvalid = false;
}, 800);
setTimeout(() => (this.pasteInvalid = false), 800);
}

public copy() {
const rawValue = this.settingService.rawVotes$.getValue();
if (rawValue === null) return;

navigator.clipboard.writeText(rawValue).then(() => {
this.copied = true;
setTimeout(() => (this.copied = false), 800);
});
}
}

0 comments on commit 6068a73

Please sign in to comment.