Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhb committed Nov 14, 2023
1 parent 2779658 commit 3e30295
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 80 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@typescript-eslint/ban-ts-comment": "off",
"no-prototype-builtins": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-extra-semi": "off",
"semi": [2, "never"]
}
}
160 changes: 82 additions & 78 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,100 +1,100 @@
import { requestUrl } from "obsidian"
import { requestUrl } from 'obsidian'

export interface SearchResponse {
data: {
search: {
edges: { node: Article }[];
edges: { node: Article }[]
pageInfo: {
hasNextPage: boolean;
};
};
};
hasNextPage: boolean
}
}
}
}

export interface DeleteArticleResponse {
"data": {
"setBookmarkArticle": {
"bookmarkedArticle": {
"id": string
}
}
data: {
setBookmarkArticle: {
bookmarkedArticle: {
id: string
}
}
}
}

export enum PageType {
Article = "ARTICLE",
Book = "BOOK",
File = "FILE",
Profile = "PROFILE",
Unknown = "UNKNOWN",
Website = "WEBSITE",
Tweet = "TWEET",
Video = "VIDEO",
Image = "IMAGE",
Article = 'ARTICLE',
Book = 'BOOK',
File = 'FILE',
Profile = 'PROFILE',
Unknown = 'UNKNOWN',
Website = 'WEBSITE',
Tweet = 'TWEET',
Video = 'VIDEO',
Image = 'IMAGE',
}

export interface Article {
id: string;
title: string;
siteName: string;
originalArticleUrl: string;
author?: string;
description?: string;
slug: string;
labels?: Label[];
highlights?: Highlight[];
updatedAt: string;
savedAt: string;
pageType: PageType;
content: string;
publishedAt?: string;
url: string;
readAt?: string;
wordsCount?: number;
readingProgressPercent: number;
isArchived: boolean;
archivedAt?: string;
contentReader?: string;
id: string
title: string
siteName: string
originalArticleUrl: string
author?: string
description?: string
slug: string
labels?: Label[]
highlights?: Highlight[]
updatedAt: string
savedAt: string
pageType: PageType
content: string
publishedAt?: string
url: string
readAt?: string
wordsCount?: number
readingProgressPercent: number
isArchived: boolean
archivedAt?: string
contentReader?: string
}

export interface Label {
name: string;
name: string
}

export enum HighlightType {
Highlight = "HIGHLIGHT",
Note = "NOTE",
Redaction = "REDACTION",
Highlight = 'HIGHLIGHT',
Note = 'NOTE',
Redaction = 'REDACTION',
}

export interface Highlight {
id: string;
quote: string | null;
annotation: string | null;
patch: string | null;
updatedAt: string;
labels?: Label[];
type: HighlightType;
highlightPositionPercent: number;
color?: string;
highlightPositionAnchorIndex: number;
id: string
quote: string | null
annotation: string | null
patch: string | null
updatedAt: string
labels?: Label[]
type: HighlightType
highlightPositionPercent: number
color?: string
highlightPositionAnchorIndex: number
}

const requestHeaders = (apiKey: string) => ({
"Content-Type": "application/json",
'Content-Type': 'application/json',
authorization: apiKey,
"X-OmnivoreClient": "obsidian-plugin",
'X-OmnivoreClient': 'obsidian-plugin',
})

export const loadArticles = async (
endpoint: string,
apiKey: string,
after = 0,
first = 10,
updatedAt = "",
query = "",
updatedAt = '',
query = '',
includeContent = false,
format = "html"
format = 'html'
): Promise<[Article[], boolean]> => {
const res = await requestUrl({
url: endpoint,
Expand Down Expand Up @@ -156,13 +156,14 @@ export const loadArticles = async (
variables: {
after: `${after}`,
first,
query: `${updatedAt ? "updated:" + updatedAt : ""
query: `${
updatedAt ? 'updated:' + updatedAt : ''
} sort:saved-asc ${query}`,
includeContent,
format,
},
}),
method: "POST",
method: 'POST',
})

const jsonRes = res.json as SearchResponse
Expand All @@ -171,13 +172,16 @@ export const loadArticles = async (
return [articles, jsonRes.data.search.pageInfo.hasNextPage]
}


export const deleteArticleById = async (endpoint: string, apiKey: string, articleId: string) => {
export const deleteArticleById = async (
endpoint: string,
apiKey: string,
articleId: string
) => {
const res = await requestUrl({
url: endpoint,
headers: requestHeaders(apiKey),
body: JSON.stringify({
query: `
url: endpoint,
headers: requestHeaders(apiKey),
body: JSON.stringify({
query: `
mutation SetBookmarkArticle($input: SetBookmarkArticleInput!) {
setBookmarkArticle(input: $input) {
... on SetBookmarkArticleSuccess {
Expand All @@ -190,19 +194,19 @@ export const deleteArticleById = async (endpoint: string, apiKey: string, articl
}
}
}`,
variables: {
input: {
"articleID": articleId,
"bookmark": false
}
},
}),
method: "POST",
variables: {
input: {
articleID: articleId,
bookmark: false,
},
},
}),
method: 'POST',
})

const jsonRes = res.json as DeleteArticleResponse
if (jsonRes.data.setBookmarkArticle.bookmarkedArticle.id === articleId) {
return true
return true
}

return false
Expand Down
4 changes: 2 additions & 2 deletions src/settings/suggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export abstract class TextInputSuggest<T> implements ISuggestOwner<T> {

open(container: HTMLElement, inputEl: HTMLElement): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(<any>this.app).keymap.pushScope(this.scope)
;(<any>this.app).keymap.pushScope(this.scope)

container.appendChild(this.suggestEl)
this.popper = createPopper(inputEl, this.suggestEl, {
Expand Down Expand Up @@ -174,7 +174,7 @@ export abstract class TextInputSuggest<T> implements ISuggestOwner<T> {

close(): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(<any>this.app).keymap.popScope(this.scope)
;(<any>this.app).keymap.popScope(this.scope)

this.suggest.setSuggestions([])
this.popper.destroy()
Expand Down

0 comments on commit 3e30295

Please sign in to comment.