Skip to content

Commit 88564d9

Browse files
author
ntwigg
committed
Move type from TextareaInfo into CommentContext.
1 parent 4ca0261 commit 88564d9

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
export interface CommentContext {
33
unique_key: string;
4+
type: string;
45
}
56

67
export interface TextareaInfo<T extends CommentContext = CommentContext> {
78
element: HTMLTextAreaElement;
8-
type: string;
99
context: T;
1010
}
1111

@@ -14,14 +14,10 @@ export interface TextareaHandler<T extends CommentContext = CommentContext> {
1414
forCommentTypes(): string[];
1515
// whenever a new `textarea` is added to any webpage, this method is called to try to find a handler for it
1616
identifyContextOf(textarea: HTMLTextAreaElement): TextareaInfo | null;
17-
18-
// Context extraction
19-
extractContext(textarea: HTMLTextAreaElement): T | null;
20-
determineType(textarea: HTMLTextAreaElement): string | null;
2117

2218
// Popup functionality helpers
2319
generateDisplayTitle(context: T): string;
24-
generateIcon(type: string): string;
20+
generateIcon(context: T): string;
2521
buildUrl(context: T, withDraft?: boolean): string;
2622
}
2723

browser-extension/src/entrypoints/content.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function initializeMaybe(textarea: HTMLTextAreaElement) {
5151
// Use registry to identify and handle this specific textarea
5252
const textareaInfo = registry.identifyTextarea(textarea)
5353
if (textareaInfo) {
54-
logger.debug('Identified textarea:', textareaInfo.type, textareaInfo.context.unique_key)
54+
logger.debug('Identified textarea:', textareaInfo.context.type, textareaInfo.context.unique_key)
5555
// TODO: Set up textarea monitoring and draft saving
5656
} else {
5757
logger.debug('No handler found for textarea')

browser-extension/src/handlers/github-handler.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ export class GitHubHandler implements TextareaHandler<GitHubContext> {
4040
const context = this.extractContext(textarea);
4141

4242
if (type && context) {
43-
return { element: textarea, type, context };
43+
return { element: textarea, context: { ...context, type } };
4444
}
4545

4646
return null;
4747
}
4848

4949

50-
extractContext(textarea: HTMLTextAreaElement): GitHubContext | null {
50+
private extractContext(textarea: HTMLTextAreaElement): GitHubContext | null {
5151
const pathname = window.location.pathname;
5252

5353
// Parse GitHub URL structure: /owner/repo/issues/123 or /owner/repo/pull/456
@@ -74,14 +74,15 @@ export class GitHubHandler implements TextareaHandler<GitHubContext> {
7474

7575
return {
7676
unique_key,
77+
type: '', // Will be set by caller
7778
domain: window.location.hostname,
7879
slug,
7980
number,
8081
commentId: commentId || undefined
8182
};
8283
}
8384

84-
determineType(textarea: HTMLTextAreaElement): GitHubCommentType | null {
85+
private determineType(textarea: HTMLTextAreaElement): GitHubCommentType | null {
8586
const pathname = window.location.pathname;
8687

8788
// New issue
@@ -130,8 +131,8 @@ export class GitHubHandler implements TextareaHandler<GitHubContext> {
130131
return `New ${window.location.pathname.includes('/issues/') ? 'issue' : 'PR'} in ${slug}`;
131132
}
132133

133-
generateIcon(type: string): string {
134-
switch (type) {
134+
generateIcon(context: GitHubContext): string {
135+
switch (context.type) {
135136
case 'GH_ISSUE_NEW':
136137
case 'GH_ISSUE_ADD_COMMENT':
137138
case 'GH_ISSUE_EDIT_COMMENT':

browser-extension/src/handlers/reddit-handler.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ export class RedditHandler implements TextareaHandler<RedditContext> {
3131
const context = this.extractContext(textarea);
3232

3333
if (type && context) {
34-
return { element: textarea, type, context };
34+
return { element: textarea, context: { ...context, type } };
3535
}
3636

3737
return null;
3838
}
3939

4040

41-
extractContext(textarea: HTMLTextAreaElement): RedditContext | null {
41+
private extractContext(textarea: HTMLTextAreaElement): RedditContext | null {
4242
const pathname = window.location.pathname;
4343

4444
// Parse Reddit URL structure: /r/subreddit/comments/postid/title/
@@ -77,13 +77,14 @@ export class RedditHandler implements TextareaHandler<RedditContext> {
7777

7878
return {
7979
unique_key,
80+
type: '', // Will be set by caller
8081
subreddit,
8182
postId,
8283
commentId: commentId || undefined
8384
};
8485
}
8586

86-
determineType(textarea: HTMLTextAreaElement): RedditCommentType | null {
87+
private determineType(textarea: HTMLTextAreaElement): RedditCommentType | null {
8788
const pathname = window.location.pathname;
8889

8990
// New post submission
@@ -114,8 +115,8 @@ export class RedditHandler implements TextareaHandler<RedditContext> {
114115
return `New post in r/${subreddit}`;
115116
}
116117

117-
generateIcon(type: string): string {
118-
switch (type) {
118+
generateIcon(context: RedditContext): string {
119+
switch (context.type) {
119120
case 'REDDIT_POST_NEW':
120121
return '📝'; // Post icon
121122
case 'REDDIT_COMMENT_NEW':

0 commit comments

Comments
 (0)