Skip to content

Commit

Permalink
Merge pull request #2 from compose-us/create-link
Browse files Browse the repository at this point in the history
add external create-link function
  • Loading branch information
TamaraBogantseva authored Jan 10, 2022
2 parents 76f3628 + 674dbeb commit 03ed8b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/lib/util/create-link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Participant } from '$lib/stores/participants-store';

type linkParams = { participant: Participant; assignment: Participant };

export function createLink(url: string, { participant, assignment }: linkParams): string {
const assignee = `${participant.firstName} ${participant.lastName}`;
const secret = btoa(`${assignment.firstName} ${assignment.lastName}`);

const params = new URLSearchParams({ assignee, secret }).toString();
return `${url}/secret/?${params}`;
}
11 changes: 6 additions & 5 deletions src/routes/participants-assignments.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { Participant, participants } from '$lib/stores/participants-store';
import { validateShuffle } from '$lib/util/validate-shuffle';
import CardLabel from '$lib/components/card-label.svelte';
import { createLink } from '$lib/util/create-link';
let pageReady = false;
let showAlert = false;
Expand Down Expand Up @@ -32,11 +33,11 @@
};
const copyLink = (index: number, assignment: Participant) => {
const participant = $participants[index];
const assignee = `${participant.firstName} ${participant.lastName}`;
const secret = btoa(`${assignment.firstName} ${assignment.lastName}`);
const params = new URLSearchParams({ assignee, secret }).toString();
navigator.clipboard.writeText(`${document.location.origin}/secret/?${params}`);
const link = createLink(document.location.origin, {
participant: $participants[index],
assignment
});
navigator.clipboard.writeText(link);
showAlert = true;
$participants[index].copied = true;
setTimeout(() => {
Expand Down

0 comments on commit 03ed8b2

Please sign in to comment.