Skip to content

Commit

Permalink
feat: UIをつくってる
Browse files Browse the repository at this point in the history
  • Loading branch information
nakasyou committed Aug 27, 2024
1 parent c15db83 commit ae422d7
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 8 deletions.
11 changes: 9 additions & 2 deletions src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<script lang="ts">
import Footer from './views/Footer.svelte';
import RealTimeSindo from './views/RealTimeSindo/index.svelte'
</script>
<div>
<RealTimeSindo />
<div class="flex flex-col h-dvh">
<div class="grow">
content content
</div>
<hr />
<div>
<Footer />
</div>
</div>
8 changes: 8 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
@import url('@unocss/reset/tailwind.css');

.hide-scrollbar::-webkit-scrollbar {
display: none;
}
.hide-scrollbar {
-ms-overflow-style: none;
scrollbar-width: none;
}
6 changes: 6 additions & 0 deletions src/utils/client/time.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const getServerTime = async (): Promise<Date> => {
const json = await fetch(`${import.meta.env.VITE_EQUAKE_API_URL}/time`).then(
(r) => r.json(),
)
return new Date(Date.parse(json.string))
}
36 changes: 36 additions & 0 deletions src/views/Footer.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<script lang="ts">
import { onDestroy, onMount } from 'svelte';
import { getServerTime } from '../utils/client/time';
import News from './News.svelte'
// hh:mm:ss
const formatter = new Intl.DateTimeFormat('ja-JP', {
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
})
let isDestroyed = false
let time: Date
onMount(() => {
const update = async () => {
time = await getServerTime()
if (isDestroyed) {
return
}
setTimeout(update, 100)
}
update()
})
onDestroy(() => {
isDestroyed = true
})
$: formattedTime = formatter.format(time)
</script>
<div class="flex items-center">
<News />
<div class="border-l-2 p-2 m-2 text-4xl font-mono">
{formattedTime}
</div>
</div>
3 changes: 3 additions & 0 deletions src/views/MainContent/index.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script lang="ts">
</script>
40 changes: 40 additions & 0 deletions src/views/News.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<script lang="ts">
import { onDestroy, onMount } from 'svelte'
// 下に流れてるニュース
const content = 'この放送は、eQuake Live が提供しています。この文字列はテスト用であり、本来はニュースを放送します。この放送は、eQuake Live が提供しています。この文字列はテスト用であり、本来はニュースを放送します。'
let divRef: HTMLDivElement
let isDestroyed = false
onMount(() => {
let lastScrollLeft = 0
const update = async () => {
divRef.scrollLeft += 1
if (divRef.scrollLeft === lastScrollLeft) {
divRef.scrollTo({
left: 0,
behavior: 'smooth',
})
setTimeout(() => {
update()
}, 1000)
return
}
lastScrollLeft = divRef.scrollLeft
if (isDestroyed) {
return
}
requestAnimationFrame(update)
}
update()
})
onDestroy(() => {
isDestroyed = true
})
</script>
<div bind:this={divRef} class="px-2 no-wrap text-xl w-full overflow-scroll hide-scrollbar whitespace-nowrap">
{content}
</div>
16 changes: 10 additions & 6 deletions src/views/RealTimeSindo/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ let projection: d3.GeoProjection
onMount(async () => {
const geojson = await fetch('/japan.geojson').then((res) => res.json())
const w = 500
const h = 500
const scale = 1200
const w = 600
const h = 600
const scale = 900
projection = d3
.geoMercator()
Expand Down Expand Up @@ -60,15 +60,19 @@ $: {
.append('circle')
.attr('cx', x)
.attr('cy', y)
.attr('r', 5)
.attr('fill', 'red')
.attr('class', 'fill-red-100')
.attr('class', 'opacity-50')
points.set(id, circle)
}
const point = points.get(id)
if (!point) continue
point.attr('r', (s.sindo + 4) * 2)
const normlizedSindo = (s.sindo + 3) / 10 // 0-1
// min: 2, max: 10
const r = 2 + (10 - 2) * normlizedSindo
point.attr('r', r)
.attr('fill', `hsl(${normlizedSindo * 240 + 120}deg, 100%, 50%)`)
}
}
}
Expand Down

0 comments on commit ae422d7

Please sign in to comment.