Skip to content

Commit 417ebbf

Browse files
committed
Clean up some code
1 parent 2b0d453 commit 417ebbf

File tree

3 files changed

+15
-38
lines changed

3 files changed

+15
-38
lines changed

src/components/Details.svelte

+5-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@
6969

7070
<div class="details">
7171
{#if selectedConcerts.length === 1}
72-
<SelectedConcertDetails selectedConcert={selectedConcerts[0]} />
72+
<SelectedConcertDetails
73+
selectedConcert={selectedConcerts[0]}
74+
on:add={(e) => addToView(e.detail.concerts, e.detail.viewName)}
75+
on:addNew={(e) => addToNewView(e.detail.concerts)}
76+
/>
7377
{:else if selectedConcerts.length === 0}
7478
<div id="centred-text">
7579
<h2>No concert selected</h2>

src/components/Dropdown.svelte

+4-8
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,14 @@
6767
div.dropdown-options :global(button) {
6868
background-color: #f0f0f0;
6969
border: 1px solid #ccc;
70-
border-radius: 5px;
70+
border-bottom: none;
7171
padding: 5px;
7272
margin: 0;
73-
text-align: left;
74-
}
75-
76-
div.dropdown-options.left :global(button) {
77-
text-align: left;
73+
text-align: left; /* Regardless of alignment, text should always be on left */
7874
}
7975
80-
div.dropdown-options.right :global(button) {
81-
text-align: right;
76+
div.dropdown-options :global(button:last-child) {
77+
border-bottom: 1px solid #ccc;
8278
}
8379
8480
div.dropdown-options :global(button:hover) {

src/components/SelectedConcertDetails.svelte

+6-29
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import Tags from "src/components/Tags.svelte";
33
import { formatDate, getPriceString } from "src/lib/utils";
44
import { type Concert } from "src/lib/bindings/Concert";
5-
import { concertViews, currentViewName } from "src/lib/stores";
5+
import { concertViews } from "src/lib/stores";
66
import Dropdown from "src/components/Dropdown.svelte";
77
88
export let selectedConcert: Concert;
@@ -17,37 +17,14 @@
1717
return validViews;
1818
}
1919
20+
// These are handled in the parent component to avoid code duplication
21+
import { createEventDispatcher } from "svelte";
22+
const dispatch = createEventDispatcher();
2023
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 });
2425
}
25-
26-
// TODO Reduce duplication with ViewList.svelte
2726
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] });
5128
}
5229
</script>
5330

0 commit comments

Comments
 (0)