From 4b4166352e17e0758f42155a32abf98309d647ae Mon Sep 17 00:00:00 2001 From: Colin Lienard Date: Sun, 26 Nov 2023 19:23:27 +0100 Subject: [PATCH] feat: add answered discussion state --- src/lib/features/createGithubNotificationData.ts | 4 ++-- src/lib/features/getGithubDiscussionData.ts | 11 ++++++++--- src/lib/helpers/getNotificationIcon.ts | 4 ++++ src/lib/icons/AnsweredDiscussionIcon.svelte | 13 +++++++++++++ src/lib/icons/index.ts | 1 + src/lib/types/common-types.ts | 2 ++ 6 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 src/lib/icons/AnsweredDiscussionIcon.svelte diff --git a/src/lib/features/createGithubNotificationData.ts b/src/lib/features/createGithubNotificationData.ts index 87988a15..d14bb73f 100644 --- a/src/lib/features/createGithubNotificationData.ts +++ b/src/lib/features/createGithubNotificationData.ts @@ -279,7 +279,7 @@ export async function createGithubNotificationData( case 'Discussion': { const data = await getDiscussionUrl(githubNotification); let { url } = data; - const { latestCommentEdge } = data; + const { latestCommentEdge, isAnswered } = data; let description: string; let author; if (!latestCommentEdge) { @@ -300,7 +300,7 @@ export async function createGithubNotificationData( author, description, url, - icon: 'discussion', + icon: isAnswered ? 'answered-discussion' : 'open-discussion', previously: previous?.description !== description ? previous : previous?.previously || undefined, type: 'discussion' diff --git a/src/lib/features/getGithubDiscussionData.ts b/src/lib/features/getGithubDiscussionData.ts index 8a1fe603..b927e604 100644 --- a/src/lib/features/getGithubDiscussionData.ts +++ b/src/lib/features/getGithubDiscussionData.ts @@ -18,6 +18,7 @@ export interface DiscussionEdge { viewerSubscription: ViewerSubscription; title: string; url: string; + isAnswered: boolean; comments: { edges: DiscussionCommentEdge[]; }; @@ -67,6 +68,7 @@ export const getLatestDiscussionCommentEdge = (comments: DiscussionCommentEdge[] export async function getDiscussionUrl(notification: GithubNotification): Promise<{ url: string; latestCommentEdge: DiscussionSubCommentEdge | undefined; + isAnswered: boolean; }> { // Get Personal Access Tokens let pat: string | undefined; @@ -93,6 +95,7 @@ export async function getDiscussionUrl(notification: GithubNotification): Promis viewerSubscription title url + isAnswered comments(last: 100) { edges { node { @@ -136,7 +139,8 @@ export async function getDiscussionUrl(notification: GithubNotification): Promis if (edges.length > 1) edges = edges.filter((edge) => edge.node.viewerSubscription === 'SUBSCRIBED'); - const comments = edges[0]?.node.comments.edges; + const node = edges[0]?.node; + const comments = node.comments.edges; let latestCommentEdge: DiscussionSubCommentEdge | undefined; if (comments?.length) { @@ -144,7 +148,8 @@ export async function getDiscussionUrl(notification: GithubNotification): Promis } return { - url: edges[0]?.node.url, - latestCommentEdge + url: node.url, + latestCommentEdge, + isAnswered: node.isAnswered }; } diff --git a/src/lib/helpers/getNotificationIcon.ts b/src/lib/helpers/getNotificationIcon.ts index a8cb8da2..2338e3f2 100644 --- a/src/lib/helpers/getNotificationIcon.ts +++ b/src/lib/helpers/getNotificationIcon.ts @@ -1,4 +1,5 @@ import { + AnsweredDiscussionIcon, ClosedIssueIcon, ClosedPullRequestIcon, CommitIcon, @@ -26,7 +27,10 @@ export function getNotificationIcon(icon: NotificationIcon) { case 'completed-issue': return CompletedIssueIcon; case 'discussion': + case 'open-discussion': return DiscussionIcon; + case 'answered-discussion': + return AnsweredDiscussionIcon; case 'draft-pr': return DraftPullRequestIcon; case 'merged-pr': diff --git a/src/lib/icons/AnsweredDiscussionIcon.svelte b/src/lib/icons/AnsweredDiscussionIcon.svelte new file mode 100644 index 00000000..f7d59c27 --- /dev/null +++ b/src/lib/icons/AnsweredDiscussionIcon.svelte @@ -0,0 +1,13 @@ + + + + diff --git a/src/lib/icons/index.ts b/src/lib/icons/index.ts index 9bc778b2..3ee81669 100644 --- a/src/lib/icons/index.ts +++ b/src/lib/icons/index.ts @@ -1,3 +1,4 @@ +export { default as AnsweredDiscussionIcon } from './AnsweredDiscussionIcon.svelte'; export { default as ArrowRightIcon } from './ArrowRightIcon.svelte'; export { default as ArrowUpIcon } from './ArrowUpIcon.svelte'; export { default as CheckIcon } from './CheckIcon.svelte'; diff --git a/src/lib/types/common-types.ts b/src/lib/types/common-types.ts index c890162f..7f42732e 100644 --- a/src/lib/types/common-types.ts +++ b/src/lib/types/common-types.ts @@ -28,6 +28,8 @@ export type NotificationIcon = | 'closed-pr' | 'release' | 'discussion' + | 'open-discussion' + | 'answered-discussion' | 'workflow' | 'workflow-fail' | 'workflow-success'