|
2 | 2 | import Tags from "src/components/Tags.svelte";
|
3 | 3 | import { formatDate, getPriceString } from "src/lib/utils";
|
4 | 4 | import { type Concert } from "src/lib/bindings/Concert";
|
5 |
| - import { concertViews, currentViewName } from "src/lib/stores"; |
| 5 | + import { concertViews } from "src/lib/stores"; |
6 | 6 | import Dropdown from "src/components/Dropdown.svelte";
|
7 | 7 |
|
8 | 8 | export let selectedConcert: Concert;
|
|
17 | 17 | return validViews;
|
18 | 18 | }
|
19 | 19 |
|
| 20 | + // These are handled in the parent component to avoid code duplication |
| 21 | + import { createEventDispatcher } from "svelte"; |
| 22 | + const dispatch = createEventDispatcher(); |
20 | 23 | function addToView(concert: Concert, viewName: string) {
|
21 |
| - const existingConcerts = $concertViews.get(viewName) as Concert[]; |
22 |
| - $concertViews.set(viewName, [...existingConcerts, concert]); |
23 |
| - $concertViews = new Map($concertViews); // trigger store update |
| 24 | + dispatch("add", { concerts: [concert], viewName }); |
24 | 25 | }
|
25 |
| -
|
26 |
| - // TODO Reduce duplication with ViewList.svelte |
27 | 26 | function addToNewView(concert: Concert) {
|
28 |
| - const newViewName = getNewViewName(); |
29 |
| - if (newViewName === null) { |
30 |
| - return; |
31 |
| - } |
32 |
| - $concertViews.set(newViewName, [concert]); |
33 |
| - $concertViews = new Map($concertViews); // Required to trigger store update |
34 |
| - $currentViewName = newViewName; |
35 |
| - } |
36 |
| -
|
37 |
| - function getNewViewName(): string | null { |
38 |
| - const newViewName = prompt("Enter a name for the new view"); |
39 |
| - if (newViewName === null) { |
40 |
| - return null; |
41 |
| - } |
42 |
| - if (newViewName === "") { |
43 |
| - alert("Please enter a name"); |
44 |
| - return null; |
45 |
| - } |
46 |
| - if ($concertViews.has(newViewName)) { |
47 |
| - alert("A view with that name already exists"); |
48 |
| - return null; |
49 |
| - } |
50 |
| - return newViewName; |
| 27 | + dispatch("addNew", { concerts: [concert] }); |
51 | 28 | }
|
52 | 29 | </script>
|
53 | 30 |
|
|
0 commit comments