StudioClock.svelte 3.05 KB
Newer Older
David Trattnig's avatar
David Trattnig committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<script>
	import { onMount } from 'svelte';

	let time = new Date();

	// these automatically update when `time`
	// changes, because of the `$:` prefix
	$: hours = time.getHours();
	$: minutes = time.getMinutes();
	$: seconds = time.getSeconds();

	onMount(() => {
		const interval = setInterval(() => {
			time = new Date();
15

David Trattnig's avatar
David Trattnig committed
16
17
18
19
20
21
		}, 1000);

		return () => {
			clearInterval(interval);
		};
	});
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

	let queryTrackservice = "trackservice";
	let currentlyPlaying;

	async function getData(query) {
		// FIXME Configure DataURL and Port
		let response = await fetch(`http://localhost:3333/api/v1/trackservice/${query}`);
		let data = await response.json();

		if (response.ok) {
			console.log(data);
			return data;
		} else {
			throw new Error(data)
		}
	}

currentlyPlaying = getData("current");
	
David Trattnig's avatar
David Trattnig committed
41
42
43
</script>

<style>
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
	#studio-clock {
		width: calc(100% - 200px);
		margin:100px;
		display: -webkit-flex;
		display: -ms-flexbox;
		display: flex;
		border: 2px solid #333;
		flex-direction: row;
	}

	#left-column {
		width: 30%;
		padding: 25px;
	}

	#right-column {
		width: 70%;
		padding: 25px;
	}

	.active {
		color: green;
	}

David Trattnig's avatar
David Trattnig committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
	svg {
		width: 100%;
		height: 100%;
	}

	.clock-face {
		stroke: #333;
		fill: white;
	}

	.minor {
		stroke: #999;
		stroke-width: 0.5;
	}

	.major {
		stroke: #333;
		stroke-width: 1;
	}

	.hour {
		stroke: #333;
	}

	.minute {
		stroke: #666;
	}

	.second, .second-counterweight {
		stroke: rgb(180,0,0);
	}

	.second-counterweight {
		stroke-width: 3;
	}
David Trattnig's avatar
David Trattnig committed
103
104
105
106
107
108
109

	footer {
		width: 100%;
		text-align: center;
		font-size: 0.8em;
		color: gray;
	}
David Trattnig's avatar
David Trattnig committed
110
111
</style>

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<div id="studio-clock">
	<div id="left-column" class="column">
		<svg viewBox='-50 -50 100 100'>
			<circle class='clock-face' r='48'/>

			<!-- markers -->
			{#each [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55] as minute}
				<line
					class='major'
					y1='35'
					y2='45'
					transform='rotate({30 * minute})'
				/>

				{#each [1, 2, 3, 4] as offset}
					<line
						class='minor'
						y1='42'
						y2='45'
						transform='rotate({6 * (minute + offset)})'
					/>
				{/each}
			{/each}

			<!-- hour hand -->
			<line
				class='hour'
				y1='2'
				y2='-20'
				transform='rotate({30 * hours + minutes / 2})'
			/>
David Trattnig's avatar
David Trattnig committed
143

144
			<!-- minute hand -->
David Trattnig's avatar
David Trattnig committed
145
			<line
146
147
148
149
				class='minute'
				y1='4'
				y2='-30'
				transform='rotate({6 * minutes + seconds / 10})'
David Trattnig's avatar
David Trattnig committed
150
			/>
151
152
153
154
155
156
157
158
159
160

			<!-- second hand -->
			<g transform='rotate({6 * seconds})'>
				<line class='second' y1='10' y2='-38'/>
				<line class='second-counterweight' y1='10' y2='2'/>
			</g>
		</svg>
	</div>

	<div id="right-column" class="column">
161
		<h2>&#9654; Playing</h2>
162
163
164
165
166
167

		{#await currentlyPlaying}
			<div class="spinner-border mt-5" role="status">
				<span class="sr-only">Loading...</span>
			</div>
		{:then value}
168
169
			<h1>{value.show.name}</h1>
			<span>Type: {value.show.type}, Host: {value.show.host}</span>
170
171
172
173
174
175
			<h3 class="active">{value.track.artist} - {value.track.title}</h3>
		{:catch error}
			<p style="color:red">{error.message}</p>
		{/await}
	</div>

David Trattnig's avatar
David Trattnig committed
176
177
178
</div>

<footer>Studio Clock is powered by <a href="https://gitlab.servus.at/autoradio">Aura Engine</a></footer>