Skip to content

Commit 7b4a394

Browse files
committed
wip: fix activity
1 parent 8b1507a commit 7b4a394

9 files changed

Lines changed: 61 additions & 40 deletions

File tree

‎.vscode/launch.json‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"type": "node-terminal",
55
"name": "Debug Web Dev",
66
"request": "launch",
7-
"command": "vp run dev",
7+
"command": "vp run dev:web",
88
"cwd": "${workspaceFolder}",
99
"serverReadyAction": {
1010
"name": "Launch Brave",
1111
"action": "startDebugging",
12-
"pattern": "Local: http://localhost:([0-9]+)",
12+
"pattern": "Local: http://.*:([0-9]+)",
1313
"killOnServerStop": true
1414
}
1515
},
@@ -25,7 +25,7 @@
2525
{
2626
"type": "swift",
2727
"request": "launch",
28-
"args": [],
28+
"args": ["-h", "0.0.0.0"],
2929
"cwd": "${workspaceFolder:website}",
3030
"name": "Debug SiteServer",
3131
"target": "SiteServer",
@@ -35,7 +35,7 @@
3535
{
3636
"type": "swift",
3737
"request": "launch",
38-
"args": [],
38+
"args": ["-h", "0.0.0.0"],
3939
"cwd": "${workspaceFolder:website}",
4040
"name": "Debug SiteServer (and Web Dev)",
4141
"target": "SiteServer",
@@ -45,7 +45,7 @@
4545
"action": "startDebugging",
4646
"name": "Debug Web Dev",
4747
"killOnServerStop": true,
48-
"pattern": "Server started and listening on 127.0.0.1:([0-9]+)"
48+
"pattern": "Server started and listening on .*:([0-9]+)"
4949
}
5050
},
5151
{

‎server/Middlewares/SiteMiddleware.swift‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct SiteMiddleware<Context: RequestContext>: RouterController {
1313
var body: some RouterMiddleware<Context> {
1414
#if DEBUG
1515
CORSMiddleware(allowOrigin: .all)
16+
TracingMiddleware()
1617
#endif
1718

1819
PublicFilesMiddleware()

‎server/Models/Activity.swift‎

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ extension Activity {
6464
public let duration: Double
6565

6666
/// timestamp of the request sent
67-
// public let timestamp: Date
67+
public let timestamp: Date
6868

6969
/// service used
7070
public let service: Service
@@ -75,22 +75,20 @@ extension Activity {
7575
}
7676
}
7777

78-
#if canImport(Foundation)
79-
extension Activity.Location: Codable {}
80-
extension Activity.Location.Residency: Codable {}
81-
extension Activity.NowPlaying.Service: Codable {}
82-
extension Activity.NowPlaying: Codable {}
83-
extension Activity: Codable {
84-
public static let encoder = {
85-
let encoder = JSONEncoder()
86-
encoder.dateEncodingStrategy = .iso8601
87-
return encoder
88-
}()
89-
90-
public static let decoder = {
91-
let decoder = JSONDecoder()
92-
decoder.dateDecodingStrategy = .iso8601
93-
return decoder
94-
}()
95-
}
96-
#endif
78+
extension Activity.Location: Codable {}
79+
extension Activity.Location.Residency: Codable {}
80+
extension Activity.NowPlaying.Service: Codable {}
81+
extension Activity.NowPlaying: Codable {}
82+
extension Activity: Codable {
83+
public static let encoder = {
84+
let encoder = JSONEncoder()
85+
encoder.dateEncodingStrategy = .iso8601
86+
return encoder
87+
}()
88+
89+
public static let decoder = {
90+
let decoder = JSONDecoder()
91+
decoder.dateDecodingStrategy = .iso8601
92+
return decoder
93+
}()
94+
}

‎server/Server.swift‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ struct Server: AsyncParsableCommand {
3737

3838
if let logLevel = envVars.get("LOG_LEVEL", as: Logger.Level.self) {
3939
logger.logLevel = logLevel
40+
} else {
41+
#if DEBUG
42+
logger.logLevel = .debug
43+
#endif
4044
}
4145

4246
router.addMiddleware {
@@ -52,4 +56,4 @@ struct Server: AsyncParsableCommand {
5256
logger: logger
5357
)
5458
}
55-
}
59+
}

‎web/assets/css/main.css‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
--text-5xl: 1.625em;
1616
--font-mono: "CommitMono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
1717
--color-primary: #ffc900;
18+
--header-height: 52px;
1819
}
1920

2021
@utility prose {

‎web/composables/use-activity.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readonly, ref } from "vue";
1+
import { ref } from "vue";
22

33
export type Activity = {
44
location?: Location;
@@ -23,20 +23,31 @@ export type NowPlaying = {
2323
album?: string;
2424
progress: number;
2525
duration: number;
26+
timestamp: Date;
2627
service: NowPlayingService;
2728
};
2829

2930
export enum NowPlayingService {
3031
appleMusic = "apple",
3132
}
3233

33-
const activity = ref(undefined as Activity | undefined);
34+
const activity = ref(undefined as Optional<Activity>);
35+
36+
const residency = Object.freeze({
37+
city: "Irvine",
38+
state: "CA",
39+
});
3440

3541
export function useActivity() {
3642
return {
37-
activity: readonly(activity),
43+
nowPlaying: computed(() => activity.value?.nowPlaying),
44+
location: computed(() => ((activity.value?.location?.city && activity.value?.location.city !== residency.city) || (activity.value?.location?.state && activity.value.location.state !== residency.state) ? activity.value?.location : undefined)),
45+
residency: computed(() => (activity.value?.location?.residency?.city || activity.value?.location?.residency?.state ? activity.value.location.residency : residency)),
3846
async fetchActivity() {
3947
const response = await $fetch<Activity>("/api/activity");
48+
if (response.nowPlaying?.timestamp && typeof response.nowPlaying.timestamp === "string") {
49+
response.nowPlaying.timestamp = new Date(response.nowPlaying.timestamp);
50+
}
4051
activity.value = response;
4152
},
4253
};

‎web/layouts/default.vue‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const copyrightFooter = `${new Date().getUTCFullYear()} erikb.dev, All rights re
88
99
useHead({
1010
titleTemplate(title) {
11-
return title ? `${title} | erikb.dev` : "erikb.dev";
11+
return title ? `${title} | ` : "" + "erikb.dev";
1212
},
1313
meta: [
1414
{ name: "charset", content: "utf-8" },
@@ -50,7 +50,7 @@ function closeMenu() {
5050
}
5151
</script>
5252
<template>
53-
<BlockSection as="header" fill :divider="false" class="fixed! top-0 z-50 border-t-0 bg-base/80! backdrop-blur-sm!">
53+
<BlockSection as="header" fill :divider="false" class="fixed! top-0 z-50 bg-base/80! backdrop-blur-sm! h-(--header-height)">
5454
<nav class="flex flex-none justify-between py-3 px-6 text-sm md:max-w-2xl mx-auto md:border-border md:border-x">
5555
<NuxtLink to="/" class="self-center" @click="closeMenu">
5656
<code class="text-white font-bold">erikb.dev()</code>

‎web/pages/index.vue‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ definePageMeta({
99
index: 0,
1010
});
1111
12-
const { activity, fetchActivity } = useActivity();
12+
const { location, residency, nowPlaying, fetchActivity } = useActivity();
1313
const { codeLang, allCodeLangs } = useCodeLang();
1414
1515
const { data: posts } = await useDevLogs();
16+
const showEmail = ref(false);
1617
1718
const postDateFormatter = new Intl.DateTimeFormat("en-US", {
1819
month: "short",
@@ -22,6 +23,8 @@ const postDateFormatter = new Intl.DateTimeFormat("en-US", {
2223
2324
onMounted(() => {
2425
if (import.meta.browser) {
26+
// only show on mounted.
27+
showEmail.value = true;
2528
fetchActivity();
2629
}
2730
});
@@ -39,27 +42,29 @@ onMounted(() => {
3942
<p class="mb-1">Mobile & Web Developer</p>
4043
<p class="text-neutral-300">
4144
<span class="text-white inline-block mr-1 size-[1em]" v-html="PhMapPinSVG"></span>
42-
<span>Irvine, CA</span>
45+
<span>{{ [residency.city, residency.state].join(", ") }}</span>
4346
</p>
44-
<p v-if="!!activity?.location?.city || !!activity?.location?.state || (!!activity?.location?.region && activity.location.residency?.city !== activity.location.city && activity.location.residency?.state != activity.location.state)" class="text-neutral-300">
47+
<p v-if="location" class="text-neutral-300">
4548
<span class="text-white inline-block mr-1 size-[1em] -scale-x-100 animate-pulse" v-html="PhNavigationArrowSVG"></span>
4649
<span>Currently in </span>
47-
<span class="font-bold italic text-white">{{ [activity.location.city || "", activity.location.state || "", activity.location.region || ""].filter((s) => !!s).join(", ") }}</span>
50+
<span class="font-bold italic text-white">{{ [location.city || "", location.state || "", location.region || ""].filter((s) => !!s).join(", ") }}</span>
4851
</p>
49-
<p v-if="activity?.nowPlaying" class="text-neutral-300">
52+
<p v-if="nowPlaying" class="text-neutral-300">
5053
<span class="text-white inline-block mr-1 size-[1em] animate-pulse" v-html="PhWaveFormSVG"></span>
5154
<span>Listening to </span>
52-
<span class="font-bold italic text-white">{{ [activity.nowPlaying.title, activity.nowPlaying.artist || ""].join(" — ") }}</span>
55+
<span class="font-bold italic text-white">{{ [nowPlaying.title, nowPlaying.artist || ""].join(" — ") }}</span>
5356
</p>
5457
<p class="pt-3 pb-5" :class="codeLang.id !== 'md' ? 'text-neutral-300' : ''">{{ codeLang.id !== "md" ? "// " : "" }}I'm a passionate software developer who builds applications using Swift and modern web technologies.</p>
5558
<div class="flex flex-row flex-wrap gap-2 text-sm text-white">
5659
<NuxtLink external to="/ebs-resume.pdf" class="border border-border px-3 py-2">
5760
<code v-if="codeLang.id == 'md'">[resume](ebs-resume.pdf)</code>
5861
<code v-else>user.resume() <span class="text-neutral-500">// ebs-resume.pdf</span></code>
5962
</NuxtLink>
60-
<NuxtLink to="mailto:me@erikb.dev" class="border border-border px-3 py-2 bg-white text-black">
61-
<code v-if="codeLang.id == 'md'">[email](me@erikb.dev)</code>
62-
<code v-else>user.email() <span class="text-neutral-700">// me@erikb.dev</span></code>
63+
<NuxtLink :to="`mailto:${showEmail ? 'me@erikb.dev' : ''}`" class="border border-border px-3 py-2 bg-white text-black">
64+
<code v-if="codeLang.id == 'md'">[email]{{ showEmail ? "(me@erikb.dev)" : "" }}</code>
65+
<code v-else
66+
>user.email() <span class="text-neutral-700">{{ showEmail ? "// me@erikb.dev" : "" }}</span></code
67+
>
6368
</NuxtLink>
6469
<NuxtLink to="https://github.com/erikbdev" class="border border-border px-3 py-2 bg-white text-black">
6570
<code v-if="codeLang.id == 'md'">[github](/erikbdev)</code>

‎web/utils/type-utils.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type Optional<T> = T | undefined;

0 commit comments

Comments
 (0)