mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Update SWR usage, move highlights temporarily
This commit is contained in:
parent
3f6e7c924a
commit
7cce65eda9
10 changed files with 41 additions and 27 deletions
|
|
@ -54,6 +54,8 @@ export function gqlFetcher(
|
|||
credentials: 'include',
|
||||
mode: 'cors',
|
||||
})
|
||||
graphQLClient.request(query, variables, requestHeaders()).then((result) => {})
|
||||
|
||||
return graphQLClient.request(query, variables, requestHeaders())
|
||||
}
|
||||
|
||||
|
|
@ -64,7 +66,6 @@ export function apiFetcher(path: string): Promise<unknown> {
|
|||
credentials: 'include',
|
||||
mode: 'cors',
|
||||
}).then((result) => {
|
||||
console.log('api fetcher result: ', result)
|
||||
return result.json()
|
||||
})
|
||||
}
|
||||
|
|
@ -96,9 +97,10 @@ export function makePublicGqlFetcher(
|
|||
// Partially apply gql variables to the request
|
||||
// This avoids using an object for the swr cache key
|
||||
export function makeGqlFetcher(
|
||||
gql: string,
|
||||
variables?: unknown
|
||||
): (query: string) => Promise<unknown> {
|
||||
return (query: string) => gqlFetcher(query, variables, true)
|
||||
return (query: string) => gqlFetcher(gql, variables, true)
|
||||
}
|
||||
|
||||
export function ssrFetcher(
|
||||
|
|
|
|||
|
|
@ -49,7 +49,8 @@ export function useGetArticleOriginalHtmlQuery({
|
|||
|
||||
const { data } = useSWRImmutable(
|
||||
slug ? [query, username, slug] : null,
|
||||
makeGqlFetcher(variables)
|
||||
makeGqlFetcher(query, variables),
|
||||
{}
|
||||
)
|
||||
|
||||
const resultData: ArticleData | undefined = data as ArticleData
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import {
|
|||
State,
|
||||
} from '../fragments/articleFragment'
|
||||
import { Highlight, highlightFragment } from '../fragments/highlightFragment'
|
||||
import { ScopedMutator } from 'swr/dist/types'
|
||||
import { ScopedMutator } from 'swr/dist/_internal'
|
||||
import { Label, labelFragment } from '../fragments/labelFragment'
|
||||
import {
|
||||
LibraryItems,
|
||||
|
|
@ -116,7 +116,8 @@ export function useGetArticleQuery({
|
|||
|
||||
const { data, error, mutate } = useSWR(
|
||||
slug ? [query, username, slug, includeFriendsHighlights] : null,
|
||||
makeGqlFetcher(variables)
|
||||
makeGqlFetcher(query, variables),
|
||||
{}
|
||||
)
|
||||
|
||||
let resultData: ArticleData | undefined = data as ArticleData
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ export function useGetArticleSavingStatus({
|
|||
`
|
||||
const key = id ? [query, id] : [query, url]
|
||||
// poll twice a second
|
||||
const { data, error } = useSWR(key, makeGqlFetcher({ id, url }), {
|
||||
const { data, error } = useSWR(key, makeGqlFetcher(query, { id, url }), {
|
||||
refreshInterval: 500,
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { gql } from "graphql-request"
|
||||
import useSWR from "swr"
|
||||
import { makeGqlFetcher } from "../networkHelpers"
|
||||
import { gql } from 'graphql-request'
|
||||
import useSWR from 'swr'
|
||||
import { makeGqlFetcher } from '../networkHelpers'
|
||||
|
||||
type DiscoverFeedsQueryResponse = {
|
||||
error: any
|
||||
|
|
@ -15,9 +15,9 @@ export type DiscoverFeed = {
|
|||
visibleName: string
|
||||
title: string
|
||||
link: string
|
||||
description?: string,
|
||||
image? : string,
|
||||
type: "rss" | "atom"
|
||||
description?: string
|
||||
image?: string
|
||||
type: 'rss' | 'atom'
|
||||
}
|
||||
|
||||
export function useGetDiscoverFeeds(): DiscoverFeedsQueryResponse {
|
||||
|
|
@ -26,16 +26,16 @@ export function useGetDiscoverFeeds(): DiscoverFeedsQueryResponse {
|
|||
discoverFeeds {
|
||||
... on DiscoverFeedSuccess {
|
||||
feeds {
|
||||
visibleName,
|
||||
id,
|
||||
title,
|
||||
link,
|
||||
description,
|
||||
image,
|
||||
visibleName
|
||||
id
|
||||
title
|
||||
link
|
||||
description
|
||||
image
|
||||
type
|
||||
}
|
||||
}
|
||||
... on DiscoverFeedError{
|
||||
... on DiscoverFeedError {
|
||||
errorCodes
|
||||
}
|
||||
}
|
||||
|
|
@ -44,12 +44,13 @@ export function useGetDiscoverFeeds(): DiscoverFeedsQueryResponse {
|
|||
|
||||
const { data, error, mutate, isValidating } = useSWR(
|
||||
[query],
|
||||
makeGqlFetcher()
|
||||
makeGqlFetcher(query),
|
||||
{}
|
||||
)
|
||||
|
||||
try {
|
||||
if (data) {
|
||||
const result = data as { discoverFeeds: { feeds: DiscoverFeed[] }}
|
||||
const result = data as { discoverFeeds: { feeds: DiscoverFeed[] } }
|
||||
const feeds = result.discoverFeeds.feeds as DiscoverFeed[]
|
||||
return {
|
||||
error,
|
||||
|
|
|
|||
|
|
@ -134,7 +134,8 @@ export function useGetHomeItems(): HomeItemResponse {
|
|||
|
||||
const { data, error, isValidating, mutate } = useSWR(
|
||||
[query, variables.first, variables.after],
|
||||
makeGqlFetcher(variables)
|
||||
makeGqlFetcher(query, variables),
|
||||
{}
|
||||
)
|
||||
|
||||
if (error) {
|
||||
|
|
|
|||
|
|
@ -40,7 +40,11 @@ export function useGetIntegrationQuery(name: string): IntegrationQueryResponse {
|
|||
}
|
||||
`
|
||||
|
||||
const { data, mutate, isValidating } = useSWR(query, makeGqlFetcher({ name }))
|
||||
const { data, mutate, isValidating } = useSWR(
|
||||
query,
|
||||
makeGqlFetcher(query, { name }),
|
||||
{}
|
||||
)
|
||||
if (!data) {
|
||||
return {
|
||||
isValidating,
|
||||
|
|
@ -50,7 +54,7 @@ export function useGetIntegrationQuery(name: string): IntegrationQueryResponse {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const result = data as IntegrationQueryResponseData
|
||||
const error = result.integration.errorCodes?.find(() => true)
|
||||
if (error) {
|
||||
|
|
|
|||
|
|
@ -93,7 +93,8 @@ export function useGetSubscriptionsQuery(
|
|||
}
|
||||
const { data, error, mutate, isValidating } = useSWR(
|
||||
[query, variables],
|
||||
makeGqlFetcher(variables)
|
||||
makeGqlFetcher(query, variables),
|
||||
{}
|
||||
)
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -40,8 +40,11 @@ export function useGetWebhookQuery(id: string): WebhookQueryResponse {
|
|||
}
|
||||
`
|
||||
|
||||
const { data, mutate, isValidating } = useSWR(query, makeGqlFetcher({ id }))
|
||||
console.log('webhook data', data)
|
||||
const { data, mutate, isValidating } = useSWR(
|
||||
query,
|
||||
makeGqlFetcher(query, { id }),
|
||||
{}
|
||||
)
|
||||
|
||||
try {
|
||||
if (data) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue