Skip to content

Commit 6fa9de5

Browse files
committed
refactor(feed-item): simplify icon condition
1 parent 63147b0 commit 6fa9de5

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

src/components/feed-item.vue

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ interface Props {
4747
}
4848
const props = defineProps<Props>();
4949
50-
const EVENT_VIEW_MAP: Record<NonNullable<FeedEvent["type"]>, Record<FeedEvent["action"], { component: Icon, color: string }>> = {
50+
interface IconInfo {
51+
component: Icon
52+
color: string
53+
}
54+
const EVENT_VIEW_MAP: Record<NonNullable<FeedEvent["type"]>, Record<FeedEvent["action"], IconInfo>> = {
5155
ForkEvent: {
5256
forked: { component: IconGitFork, color: "var(--base)" }
5357
},
@@ -73,13 +77,8 @@ const EVENT_VIEW_MAP: Record<NonNullable<FeedEvent["type"]>, Record<FeedEvent["a
7377
starred: { component: IconStar, color: "var(--accent)" }
7478
}
7579
};
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;
82-
})();
80+
const DEFAULT_ICON = { component: IconCalendarEvent, color: "var(--base)" } as const satisfies IconInfo;
81+
const icon = props.data.type ? EVENT_VIEW_MAP[props.data.type][props.data.action] ?? DEFAULT_ICON : DEFAULT_ICON;
8382
</script>
8483
<style lang="scss">
8584
.feed-item {

0 commit comments

Comments
 (0)