Skip to content

Commit 51384c3

Browse files
committed
feat(feed-item): update icon mappings
1 parent f6d1933 commit 51384c3

2 files changed

Lines changed: 38 additions & 32 deletions

File tree

src/assets/global.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
--base: #aaa;
66
--positive: #008000;
77
--negative: #e00000;
8+
--success: #3fb950;
9+
--done: #ab7df8;
10+
--danger: #f85149;
11+
--accent: #e3b341;
812
&[data-theme="github"] {
913
--base: #7d8590;
1014
--background: #0d1117;

src/components/feed-item.vue

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<li class="feed-item">
33
<time class="feed-item__timestamp">{{ data.date }}:</time>
4-
<component :is="iconComponent" :style="{ stroke: iconColor }" class="feed-item__icon" />
4+
<component :is="icon.component" :style="{ stroke: icon.color }" class="feed-item__icon" />
55
<span v-if="data.username.includes('github-actions')" class="feed-item__accent">
66
{{ data.username }}
77
</span>
@@ -32,7 +32,9 @@ import {
3232
IconCircleDot,
3333
IconEye,
3434
IconGitFork,
35+
IconGitMerge,
3536
IconGitPullRequest,
37+
IconGitPullRequestClosed,
3638
IconStar,
3739
IconTag,
3840
IconUser,
@@ -45,38 +47,38 @@ interface Props {
4547
}
4648
const props = defineProps<Props>();
4749
48-
const iconComponent: Icon = (() => {
49-
switch (props.data.type) {
50-
case "ForkEvent": return IconGitFork;
51-
case "IssuesEvent": return IconCircleDot;
52-
case "MemberEvent": return IconUser;
53-
case "PublicEvent": return IconEye;
54-
case "PullRequestEvent": return IconGitPullRequest;
55-
case "ReleaseEvent": return IconTag;
56-
case "WatchEvent": return IconStar;
57-
default: return IconCalendarEvent;
58-
}
59-
})();
60-
const iconColor: string | undefined = (() => {
61-
switch (props.data.action) {
62-
case "opened issue":
63-
case "opened pull request":
64-
case "published release":
65-
return "#3fb950"; // green
66-
case "merged pull request":
67-
return "#ab7df8"; // purple
68-
case "closed issue":
69-
case "closed pull request":
70-
return "#f85149"; // red
71-
case "made public":
72-
case "starred":
73-
return "#e3b341"; // yellow
74-
case "forked":
75-
case "joined":
76-
return "#9198a1"; // gray
77-
default:
78-
return undefined;
50+
const EVENT_VIEW_MAP: Record<NonNullable<FeedEvent["type"]>, Record<FeedEvent["action"], { component: Icon, color: string }>> = {
51+
ForkEvent: {
52+
forked: { component: IconGitFork, color: "var(--base)" }
53+
},
54+
IssuesEvent: {
55+
"opened issue": { component: IconCircleDot, color: "var(--success)" },
56+
"closed issue": { component: IconCircleDot, color: "var(--danger)" }
57+
},
58+
MemberEvent: {
59+
joined: { component: IconUser, color: "var(--base)" }
60+
},
61+
PublicEvent: {
62+
"made public": { component: IconEye, color: "var(--accent)" }
63+
},
64+
PullRequestEvent: {
65+
"opened pull request": { component: IconGitPullRequest, color: "var(--success)" },
66+
"closed pull request": { component: IconGitPullRequestClosed, color: "var(--danger)" },
67+
"merged pull request": { component: IconGitMerge, color: "var(--done)" }
68+
},
69+
ReleaseEvent: {
70+
"published release": { component: IconTag, color: "var(--success)" }
71+
},
72+
WatchEvent: {
73+
starred: { component: IconStar, color: "var(--accent)" }
7974
}
75+
};
76+
const DEFAULT_ICON = { component: IconCalendarEvent, color: "var(--base)" } as const;
77+
78+
const icon = (() => {
79+
const { type, action } = props.data;
80+
if (!type) return DEFAULT_ICON;
81+
return EVENT_VIEW_MAP[type][action] ?? DEFAULT_ICON;
8082
})();
8183
</script>
8284
<style lang="scss">

0 commit comments

Comments
 (0)