Skip to content

Commit e93730e

Browse files
authored
Merge pull request #47 from mbaraa/feat/add-to-playlist-popup
Feat: add to playlist popup
2 parents f3912a5 + b41dc28 commit e93730e

File tree

11 files changed

+123
-49
lines changed

11 files changed

+123
-49
lines changed

.air.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
root = "."
2+
3+
[build]
4+
bin = "./dankmuzikk serve"
5+
cmd = "go generate && go build"
6+
delay = 100
7+
exclude_dir = [
8+
"assets",
9+
"tmp",
10+
"vendor",
11+
"_db",
12+
"_serve",
13+
"node_modules",
14+
"ytscraper",
15+
"ytdl",
16+
]
17+
exclude_file = []
18+
exclude_regex = [".*_templ.go"]
19+
exclude_unchanged = false
20+
follow_symlink = false
21+
full_bin = ""
22+
include_dir = []
23+
include_ext = ["go", "tpl", "tmpl", "templ", "html", "js", "css"]
24+
kill_delay = "0s"
25+
log = "build-errors.log"
26+
send_interrupt = true
27+
stop_on_error = true
28+
29+
[color]
30+
app = ""
31+
build = "yellow"
32+
main = "magenta"
33+
runner = "green"
34+
watcher = "cyan"
35+
36+
[log]
37+
time = false
38+
39+
[misc]
40+
clean_on_exit = false

Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@ BINARY_NAME=dankmuzikk
66
build:
77
npm i && \
88
go mod tidy && \
9-
templ generate && \
109
go generate && \
1110
go build -ldflags="-w -s" -o ${BINARY_NAME}
1211

1312
generate:
14-
go generate && \
15-
templ generate
13+
go generate
1614

1715
init:
1816
npm i && \
1917
go get && \
2018
go generate && \
21-
templ generate && \
2219
go run main.go migrate
2320

2421
seed:
@@ -27,7 +24,7 @@ seed:
2724
# dev runs the development server where it builds the tailwind css sheet,
2825
# and compiles the project whenever a file is changed.
2926
dev:
30-
templ generate --watch --cmd="./run.sh dev"
27+
go run github.com/cosmtrek/[email protected]
3128

3229
clean:
3330
go clean

run.sh

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
#!/bin/sh
22

3-
dev() {
4-
# This function is used to compile tailwind's style sheet, and run the web server.
5-
# Also this is supposed to be ran using templ's CLI, i.e.
6-
# templ generate --watch --cmd="./run.sh"
7-
# idk, that's it.
8-
9-
go generate
10-
go run . serve
11-
}
12-
133
beta() {
144
./dankmuzikk serve
155
}

views/components/loading/loading.templ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ templ Loading() {
44
<div
55
class={
66
"absolute", "top-0", "left-0", "z-[200]", "w-screen", "h-screen",
7-
"bg-accent-trans-30", "flex", "justify-center", "items-center",
7+
"bg-accent-trans-30", "flex", "justify-center", "items-center", "z-50",
88
}
99
>
1010
<div class={ "loader", "!h-32", "!w-32" }></div>

views/components/playlist/new_playlis_popover.templ

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,18 @@ templ newPlaylistPopover() {
2424
name="title"
2525
placeholder="Enter the playlist's title"
2626
autofocus
27+
required
2728
/>
2829
<button
2930
class={
3031
"bg-primary", "text-secondary", "rounded-[50px]", "py-[5px]",
3132
"px-[60px]", "w-full",
3233
}
3334
type="submit"
34-
onClick={ hideNewPlayListPopover() }
3535
>Create playlist</button>
3636
</form>
3737
}
3838

3939
templ newPlaylistPopoverButton() {
4040
New playlist
4141
}
42-
43-
script hideNewPlayListPopover() {
44-
document.getElementById("popover-new-playlist")
45-
.style.display = "none";
46-
}

views/components/playlist/options.templ

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import (
55
"dankmuzikk/entities"
66
"dankmuzikk/views/components/popover"
77
"dankmuzikk/models"
8+
"dankmuzikk/views/icons"
89
)
910

1011
templ PlaylistsOptionsPopover(playlist entities.Playlist) {
11-
@popover.Popover("playlist-"+playlist.PublicId, "Playlist options", playlistOptionsButton(), playlistOptions(playlist))
12+
@popover.Popover("playlist-"+playlist.PublicId, "Playlist options", icons.Options(), playlistOptions(playlist))
1213
}
1314

1415
templ playlistOptions(playlist entities.Playlist) {
@@ -48,14 +49,6 @@ templ playlistOptions(playlist entities.Playlist) {
4849
</div>
4950
}
5051

51-
templ playlistOptionsButton() {
52-
<svg width="21" height="21" viewBox="0 0 21 21" fill="none" xmlns="http://www.w3.org/2000/svg">
53-
<circle cx="10.5" cy="2.5" r="2.5" fill="var(--secondary-color)"></circle>
54-
<circle cx="10.5" cy="10.5" r="2.5" fill="var(--secondary-color)"></circle>
55-
<circle cx="10.5" cy="18.5" r="2.5" fill="var(--secondary-color)"></circle>
56-
</svg>
57-
}
58-
5952
templ publicPlaylistToggle(publicId string, isPublic bool) {
6053
<div
6154
class={ "flex", "gap-x-2", "items-center", "cursor-pointer" }
@@ -75,7 +68,7 @@ templ publicPlaylistToggle(publicId string, isPublic bool) {
7568
"/api/playlist/public?playlist-id=%s", publicId,
7669
),
7770
}
78-
title="Toggeling this will change the playlist's visibility!"
71+
title="Toggling this will change the playlist's visibility!"
7972
>
8073
<div
8174
id={ fmt.Sprintf("public-playlist-%s", publicId) }

views/components/playlist/popover.templ renamed to views/components/playlist/popup.templ

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@ package playlist
33
import (
44
"fmt"
55
"dankmuzikk/entities"
6-
"dankmuzikk/views/components/popover"
6+
"dankmuzikk/views/components/popup"
77
)
88

9-
templ PlaylistsPopover(index int, songId string, playlists []entities.Playlist, songsInPlaylists map[string]bool) {
10-
@popover.Popover(fmt.Sprint(index), "Add to playlist", popoverButton(), playlistsSelector(songId, playlists, songsInPlaylists))
9+
templ PlaylistsPopup(index int, songId string, playlists []entities.Playlist, songsInPlaylists map[string]bool) {
10+
@popup.Popup(fmt.Sprint(index), "Add to playlist", popoverButton(), playlistsSelector(songId, playlists, songsInPlaylists))
1111
}
1212

1313
templ playlistsSelector(songId string, playlists []entities.Playlist, songsInPlaylists map[string]bool) {
14-
<div class={ "min-w-[250px]", "bg-accent-trans-30", "backdrop-blur-md", "p-3", "rounded-[10px]", "text-secondary" }>
15-
<h2 class={ "text-lg" }>Save this song to...</h2>
14+
<div
15+
class={
16+
"min-w-[350px]", "bg-accent-trans-30", "backdrop-blur-md", "p-3", "text-secondary",
17+
"rounded-b-[10px]", "rounded-l-[10px]",
18+
}
19+
>
20+
<h2 class={ "text-xl", "font-bold" }>Save this song to...</h2>
1621
<div class={ "my-2" }></div>
1722
<ul class={ "flex", "flex-col", "gap-y-2" }>
1823
if playlists == nil || len(playlists) == 0 {

views/components/popup/popup.templ

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package popup
2+
3+
import "fmt"
4+
5+
templ Popup(id, title string, button, child templ.Component) {
6+
<button
7+
class={
8+
"popup-trigger", "p-2", "rounded-md", "hover:bg-accent-trans-20",
9+
"flex", "justify-center", "items-center",
10+
}
11+
title={ title }
12+
type="button"
13+
onClick={ toggleTheThing(id) }
14+
>
15+
@button
16+
</button>
17+
<dialog
18+
id={ fmt.Sprintf("popup-%s", id) }
19+
class={ "bg-[#ffffff00]" }
20+
>
21+
<form
22+
class={ }
23+
>
24+
<div class={ "w-full","flex", "justify-end" }>
25+
<button
26+
formmethod="dialog"
27+
type="submit"
28+
class={
29+
"bg-[#DE3333]", "hover:bg-white", "text-white", "hover:text-[#DE3333]",
30+
"popup-trigger", "p-[5px]", "rounded-t-md", "text-lg", "font-medium",
31+
}
32+
>Close</button>
33+
</div>
34+
@child
35+
</form>
36+
</dialog>
37+
}
38+
39+
script toggleTheThing(id string) {
40+
const popup = document.getElementById(`popup-${id}`);
41+
popup.showModal();
42+
popup.addEventListener("click", e => {
43+
const rect = popup.getBoundingClientRect()
44+
if (
45+
e.clientX < rect.left ||
46+
e.clientX > rect.right ||
47+
e.clientY < rect.top ||
48+
e.clientY > rect.bottom
49+
) {
50+
popup.close()
51+
}
52+
})
53+
}

views/icons/options.templ

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package icons
2+
3+
templ Options() {
4+
<svg width="21" height="21" viewBox="0 0 21 21" fill="none" xmlns="http://www.w3.org/2000/svg">
5+
<circle cx="10.5" cy="2.5" r="2.5" fill="var(--secondary-color)"></circle>
6+
<circle cx="10.5" cy="10.5" r="2.5" fill="var(--secondary-color)"></circle>
7+
<circle cx="10.5" cy="18.5" r="2.5" fill="var(--secondary-color)"></circle>
8+
</svg>
9+
}

views/pages/playlist.templ

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"dankmuzikk/views/components/popover"
88
"dankmuzikk/models"
99
"dankmuzikk/views/components/playlist"
10+
"dankmuzikk/views/icons"
1011
)
1112

1213
templ Playlist(pl entities.Playlist) {
@@ -97,9 +98,9 @@ templ Playlist(pl entities.Playlist) {
9798
</div>
9899
<div>
99100
if isMobile, ok := ctx.Value("is-mobile").(bool); ok && isMobile {
100-
@popover.Popover(song.YtId, "Options", songOptionsToggle(), songOptionsMobile(song, pl.PublicId))
101+
@popover.Popover(song.YtId, "Options", icons.Options(), songOptionsMobile(song, pl.PublicId))
101102
} else {
102-
@popover.Popover(song.YtId, "Options", songOptionsToggle(), songOptions(song, pl.PublicId))
103+
@popover.Popover(song.YtId, "Options", icons.Options(), songOptions(song, pl.PublicId))
103104
}
104105
</div>
105106
</div>
@@ -113,15 +114,6 @@ templ Playlist(pl entities.Playlist) {
113114
</div>
114115
</main>
115116
<input id="clipboard-text-blyat" type="text" hidden/>
116-
// <div class={ "hidden" }><textarea id="clipboard-text-blyat"></textarea></div>
117-
}
118-
119-
templ songOptionsToggle() {
120-
<svg width="21" height="21" viewBox="0 0 21 21" fill="none" xmlns="http://www.w3.org/2000/svg">
121-
<circle cx="10.5" cy="2.5" r="2.5" fill="var(--secondary-color)"></circle>
122-
<circle cx="10.5" cy="10.5" r="2.5" fill="var(--secondary-color)"></circle>
123-
<circle cx="10.5" cy="18.5" r="2.5" fill="var(--secondary-color)"></circle>
124-
</svg>
125117
}
126118

127119
templ songOptions(song entities.Song, playlistId string) {

0 commit comments

Comments
 (0)