Skip to content

Commit 3ed7d5f

Browse files
committed
Remove greebles.
1 parent d0f705d commit 3ed7d5f

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { BackgroundMessage, CommentDraft, CommentSpot } from '../lib/enhancer'
1+
import type { CommentDraft, CommentEvent, CommentSpot } from '../lib/enhancer'
22
import { JsonMap } from '../lib/jsonmap'
33

44
interface Tab {
@@ -15,29 +15,32 @@ interface CommentState {
1515
drafts: [number, CommentDraft][]
1616
}
1717

18-
const _states = new JsonMap<TabAndSpot, CommentState>()
19-
20-
browser.runtime.onMessage.addListener((message: BackgroundMessage, sender) => {
21-
if (message.action === 'COMMENT_EVENT' && sender.tab?.id && sender.tab?.windowId) {
18+
const states = new JsonMap<TabAndSpot, CommentState>()
19+
browser.runtime.onMessage.addListener((message: CommentEvent, sender) => {
20+
if (
21+
(message.type === 'ENHANCED' || message.type === 'DESTROYED') &&
22+
sender.tab?.id &&
23+
sender.tab?.windowId
24+
) {
2225
const tab: Tab = {
2326
tabId: sender.tab.id,
2427
windowId: sender.tab.windowId,
2528
}
2629

2730
const tabAndSpot: TabAndSpot = {
28-
spot: message.event.spot,
31+
spot: message.spot,
2932
tab,
3033
}
3134

32-
if (message.event.type === 'ENHANCED') {
35+
if (message.type === 'ENHANCED') {
3336
const commentState: CommentState = {
3437
drafts: [],
35-
spot: message.event.spot,
38+
spot: message.spot,
3639
tab,
3740
}
38-
_states.set(tabAndSpot, commentState)
39-
} else if (message.event.type === 'DESTROYED') {
40-
_states.delete(tabAndSpot)
41+
states.set(tabAndSpot, commentState)
42+
} else if (message.type === 'DESTROYED') {
43+
states.delete(tabAndSpot)
4144
}
4245
}
4346
})

browser-extension/src/entrypoints/content.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CONFIG, type ModeType } from '../lib/config'
2-
import type { BackgroundMessage, CommentSpot } from '../lib/enhancer'
2+
import type { CommentEvent, CommentSpot } from '../lib/enhancer'
33
import { logger } from '../lib/logger'
44
import { EnhancerRegistry, TextareaRegistry } from '../lib/registries'
55
import { githubPrNewCommentContentScript } from '../playgrounds/github-playground'
@@ -8,9 +8,10 @@ const enhancers = new EnhancerRegistry()
88
const enhancedTextareas = new TextareaRegistry()
99

1010
function sendEventToBackground(type: 'ENHANCED' | 'DESTROYED', spot: CommentSpot): void {
11-
const message: BackgroundMessage = {
12-
action: 'COMMENT_EVENT',
13-
event: { spot, type },
11+
const message: CommentEvent = {
12+
draft: undefined,
13+
spot,
14+
type,
1415
}
1516
browser.runtime.sendMessage(message).catch((error) => {
1617
logger.debug('Failed to send event to background:', error)

browser-extension/src/lib/enhancer.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ export interface CommentEvent {
2323
draft: CommentDraft | undefined
2424
}
2525

26-
export interface BackgroundMessage {
27-
action: 'COMMENT_EVENT'
28-
event: {
29-
type: Extract<CommentEventType, 'ENHANCED' | 'DESTROYED'>
30-
spot: CommentSpot
31-
}
32-
}
33-
3426
/** Wraps the textareas of a given platform with Gitcasso's enhancements. */
3527
export interface CommentEnhancer<Spot extends CommentSpot = CommentSpot> {
3628
/** Guarantees to only return a type within this list. */

0 commit comments

Comments
 (0)