Skip to content

Commit

Permalink
refactor(provider): use strings instead of enum
Browse files Browse the repository at this point in the history
  • Loading branch information
bdbch committed Dec 10, 2024
1 parent 3fbe9c8 commit c8ba040
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
11 changes: 5 additions & 6 deletions packages/provider/src/TiptapCollabProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {

import { TiptapCollabProviderWebsocket } from './TiptapCollabProviderWebsocket.js'
import {
ThreadType,
type DeleteCommentOptions,
type DeleteThreadOptions,
type GetThreadsOptions,
Expand All @@ -21,7 +20,7 @@ const defaultDeleteCommentOptions: DeleteCommentOptions = {
}

const defaultGetThreadsOptions: GetThreadsOptions = {
types: [ThreadType.Unarchived],
types: ['unarchived'],
}

const defaultDeleteThreadOptions: DeleteThreadOptions = {
Expand Down Expand Up @@ -148,16 +147,16 @@ export class TiptapCollabProvider extends HocuspocusProvider {

const threads = this.getYThreads().toJSON() as TCollabThread<Data, CommentData>[]

if (types?.includes(ThreadType.Archived) && types?.includes(ThreadType.Unarchived)) {
if (types?.includes('archived') && types?.includes('unarchived')) {
return threads
}

return threads.filter(currentThead => {
if (types?.includes(ThreadType.Archived) && currentThead.deletedAt) {
if (types?.includes('archived') && currentThead.deletedAt) {
return true
}

if (types?.includes(ThreadType.Unarchived) && !currentThead.deletedAt) {
if (types?.includes('unarchived') && !currentThead.deletedAt) {
return true
}

Expand All @@ -175,7 +174,7 @@ export class TiptapCollabProvider extends HocuspocusProvider {

let i = 0
// eslint-disable-next-line no-restricted-syntax
for (const thread of this.getThreads({ types: [ThreadType.Archived, ThreadType.Unarchived] })) {
for (const thread of this.getThreads({ types: ['archived', 'unarchived'] })) {
if (thread.id === id) {
index = i
break
Expand Down
15 changes: 4 additions & 11 deletions packages/provider/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,10 @@ export type DeleteThreadOptions = {
force?: boolean,
}

export enum ThreadType {
/**
* A archived thread
*/
Archived = 'archived',

/**
* A unarchived thread
*/
Unarchived = 'unarchived',
}
/**
* The type of thread
*/
export type ThreadType = 'archived' | 'unarchived'

export type GetThreadsOptions = {
/**
Expand Down

0 comments on commit c8ba040

Please sign in to comment.