Skip to content

Commit 5489ae2

Browse files
committed
feat(feed): add action icons
1 parent c7e2ef8 commit 5489ae2

3 files changed

Lines changed: 67 additions & 9 deletions

File tree

src/assets/global.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ svg {
118118
.tabler-icon {
119119
width: 1.2em;
120120
height: 1.2em;
121-
stroke-width: 2;
122121
}
123122
a {
124123
color: inherit;

src/pages/feed.vue

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
No recent events
55
</span>
66
<ul v-else>
7-
<li v-for="{ date, username, action, repo, id, eventUrl } in events" :key="id">
8-
<time>{{ date }}</time>:
7+
<li v-for="{ date, type, username, action, repo, id, eventUrl } in events" :key="id">
8+
<time>{{ date }}:</time>
9+
<component :is="getIconComponent(type)" :style="composeIconStyle(action)" class="user-feed__icon" />
910
<a
1011
:href="`https://github.com/${username}`"
1112
target="_blank"
@@ -29,9 +30,59 @@
2930
</section>
3031
</template>
3132
<script setup lang="ts">
32-
import { useEventsStore } from "@/store/events";
33+
import type { CSSProperties } from "vue";
34+
import {
35+
IconCalendarEvent,
36+
IconCircleDot,
37+
IconEye,
38+
IconGitFork,
39+
IconGitPullRequest,
40+
IconStar,
41+
IconTag,
42+
IconUser,
43+
type Icon
44+
} from "@tabler/icons-vue";
45+
import { useEventsStore, type FeedEvent } from "@/store/events";
3346
3447
const { events, amount } = useEventsStore();
48+
49+
function getIconComponent(type: FeedEvent["type"]): Icon {
50+
switch (type) {
51+
case "ForkEvent": return IconGitFork;
52+
case "IssuesEvent": return IconCircleDot;
53+
case "MemberEvent": return IconUser;
54+
case "PublicEvent": return IconEye;
55+
case "PullRequestEvent": return IconGitPullRequest;
56+
case "ReleaseEvent": return IconTag;
57+
case "WatchEvent": return IconStar;
58+
default: return IconCalendarEvent;
59+
}
60+
}
61+
function getIconColor(action: FeedEvent["action"]): string | null {
62+
switch (action) {
63+
case "opened issue":
64+
case "opened pull request":
65+
case "published release":
66+
return "#3fb950"; // green
67+
case "merged pull request":
68+
return "#ab7df8"; // purple
69+
case "closed issue":
70+
case "closed pull request":
71+
return "#f85149"; // red
72+
case "made public":
73+
case "starred":
74+
return "#e3b341"; // yellow
75+
case "forked":
76+
case "joined":
77+
return "#9198a1"; // gray
78+
default:
79+
return null;
80+
}
81+
}
82+
function composeIconStyle(action: FeedEvent["action"]): CSSProperties | null {
83+
const color = getIconColor(action);
84+
return color ? { stroke: color } : null;
85+
}
3586
</script>
3687
<style lang="scss">
3788
.user-feed {
@@ -50,5 +101,11 @@ const { events, amount } = useEventsStore();
50101
}
51102
}
52103
}
104+
&__icon {
105+
width: 1rem;
106+
height: 1rem;
107+
margin-inline: .25rem;
108+
vertical-align: bottom;
109+
}
53110
}
54111
</style>

src/store/events.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ function getActionString({ type, payload }: RawEvent): string {
2626
switch (type) {
2727
case "ForkEvent": return "forked";
2828
case "IssuesEvent": return `${payload.action} issue`;
29-
case "ReleaseEvent": return `${payload.action} release`;
3029
case "MemberEvent": return "joined";
3130
case "PublicEvent": return "made public";
3231
case "PullRequestEvent": return `${payload.action} pull request`;
32+
case "ReleaseEvent": return `${payload.action} release`;
3333
case "WatchEvent": return "starred";
3434
default: return type ?? "[unknown action]";
3535
}
@@ -56,12 +56,13 @@ function composeEventUrl(event: RawEvent): string | null {
5656
return null;
5757
}
5858

59-
interface FeedEvent {
60-
id: string
59+
export interface FeedEvent {
60+
id: RawEvent["id"]
61+
type: RawEvent["type"]
62+
repo: RawEvent["repo"]["name"]
6163
date: string
6264
username: string
6365
action: string
64-
repo: string
6566
eventUrl?: string | null
6667
}
6768

@@ -98,10 +99,11 @@ export const useEventsStore = createGlobalState(() => {
9899
) { return acc; }
99100
const feedEvent: FeedEvent = {
100101
id: event.id,
102+
type: event.type,
103+
repo: event.repo.name,
101104
date: dayjs(event.created_at).format("DD MMMM HH:mm"),
102105
username: event.actor.display_login ?? event.actor.login,
103106
action: getActionString(event),
104-
repo: event.repo.name,
105107
eventUrl: composeEventUrl(event)
106108
};
107109
acc.push(feedEvent);

0 commit comments

Comments
 (0)