Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add answered discussion state #232

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/features/createGithubNotificationData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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'
Expand Down
11 changes: 8 additions & 3 deletions src/lib/features/getGithubDiscussionData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface DiscussionEdge {
viewerSubscription: ViewerSubscription;
title: string;
url: string;
isAnswered: boolean;
comments: {
edges: DiscussionCommentEdge[];
};
Expand Down Expand Up @@ -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;
Expand All @@ -93,6 +95,7 @@ export async function getDiscussionUrl(notification: GithubNotification): Promis
viewerSubscription
title
url
isAnswered
comments(last: 100) {
edges {
node {
Expand Down Expand Up @@ -136,15 +139,17 @@ 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) {
latestCommentEdge = getLatestDiscussionCommentEdge(comments);
}

return {
url: edges[0]?.node.url,
latestCommentEdge
url: node.url,
latestCommentEdge,
isAnswered: node.isAnswered
};
}
4 changes: 4 additions & 0 deletions src/lib/helpers/getNotificationIcon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
AnsweredDiscussionIcon,
ClosedIssueIcon,
ClosedPullRequestIcon,
CommitIcon,
Expand Down Expand Up @@ -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':
Expand Down
13 changes: 13 additions & 0 deletions src/lib/icons/AnsweredDiscussionIcon.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<svg viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M13 4H2a1 1 0 0 0-1 1v7a1 1 0 0 0 1 1h1a1 1 0 0 1 1 1v1.586c0 .89 1.077 1.337 1.707.707l3-3A1 1 0 0 1 9.414 13H13a1 1 0 0 0 1-1V5a1 1 0 0 0-1-1Z"
stroke="#9C73EF"
stroke-width="1.5"
/>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="m11.44 15.5 2.323 2.323c1.102 1.103 2.987.322 2.987-1.237V15a.25.25 0 0 1 .25-.25h1A1.75 1.75 0 0 0 19.75 13V6A1.75 1.75 0 0 0 18 4.25h-1.58c.052.242.08.493.08.75v.75H18a.25.25 0 0 1 .25.25v7a.25.25 0 0 1-.25.25h-1c-.294 0-.57.072-.814.2a3.51 3.51 0 0 1-.901 1.202 1.733 1.733 0 0 0-.035.348v1.586a.25.25 0 0 1-.427.177l-1.301-1.302c-.17.026-.345.039-.522.039h-1.56Z"
fill="#9C73EF"
/>
</svg>
1 change: 1 addition & 0 deletions src/lib/icons/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 2 additions & 0 deletions src/lib/types/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export type NotificationIcon =
| 'closed-pr'
| 'release'
| 'discussion'
| 'open-discussion'
| 'answered-discussion'
| 'workflow'
| 'workflow-fail'
| 'workflow-success'
Expand Down