Merge remote-tracking branch 'origin/auth-fixes' into prepare-inbox
This commit is contained in:
commit
62926197d1
|
@ -1,5 +1,5 @@
|
||||||
overwrite: true
|
overwrite: true
|
||||||
schema: 'http://v2.discours.io/graphql'
|
schema: 'https://testapi.discours.io'
|
||||||
generates:
|
generates:
|
||||||
src/graphql/introspec.gen.ts:
|
src/graphql/introspec.gen.ts:
|
||||||
plugins:
|
plugins:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { HomeView, PRERENDERED_ARTICLES_COUNT } from '../Views/Home'
|
import { HomeView, PRERENDERED_ARTICLES_COUNT, RANDOM_TOPICS_COUNT } from '../Views/Home'
|
||||||
import { PageWrap } from '../_shared/PageWrap'
|
import { PageWrap } from '../_shared/PageWrap'
|
||||||
import type { PageProps } from '../types'
|
import type { PageProps } from '../types'
|
||||||
import { createSignal, onCleanup, onMount, Show } from 'solid-js'
|
import { createSignal, onCleanup, onMount, Show } from 'solid-js'
|
||||||
|
@ -15,8 +15,8 @@ export const HomePage = (props: PageProps) => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await loadShouts({ filters: { visibility: 'public' }, limit: PRERENDERED_ARTICLES_COUNT, offset: 0 })
|
await loadShouts({ filters: { visibility: 'public' }, limit: PRERENDERED_ARTICLES_COUNT })
|
||||||
await loadRandomTopics()
|
await loadRandomTopics({ amount: RANDOM_TOPICS_COUNT })
|
||||||
|
|
||||||
setIsLoaded(true)
|
setIsLoaded(true)
|
||||||
})
|
})
|
||||||
|
|
|
@ -25,6 +25,7 @@ type HomeProps = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PRERENDERED_ARTICLES_COUNT = 5
|
export const PRERENDERED_ARTICLES_COUNT = 5
|
||||||
|
export const RANDOM_TOPICS_COUNT = 12
|
||||||
const CLIENT_LOAD_ARTICLES_COUNT = 29
|
const CLIENT_LOAD_ARTICLES_COUNT = 29
|
||||||
const LOAD_MORE_PAGE_SIZE = 16 // Row1 + Row3 + Row2 + Beside (3 + 1) + Row1 + Row 2 + Row3
|
const LOAD_MORE_PAGE_SIZE = 16 // Row1 + Row3 + Row2 + Beside (3 + 1) + Row1 + Row 2 + Row3
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import { cacheExchange, CacheExchangeOpts } from '@urql/exchange-graphcache'
|
import { cacheExchange, CacheExchangeOpts } from '@urql/exchange-graphcache'
|
||||||
// import schema from './introspec.gen'
|
|
||||||
|
|
||||||
|
// import schema from './introspec.gen'
|
||||||
|
// NOTE: include codegened introspection schema when needed
|
||||||
|
|
||||||
|
// TODO: use urql-provided caching
|
||||||
export const cache = cacheExchange({
|
export const cache = cacheExchange({
|
||||||
// TODO: include introspection schema when needed
|
|
||||||
keys: {
|
keys: {
|
||||||
Shout: (data) => data.slug,
|
Shout: (data) => data.slug,
|
||||||
Author: (data) => data.slug,
|
Author: (data) => data.slug,
|
||||||
|
|
30
src/graphql/client.ts
Normal file
30
src/graphql/client.ts
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import { createClient } from '@urql/core'
|
||||||
|
import { isDev } from '../utils/config'
|
||||||
|
|
||||||
|
const localClient = (options) => {
|
||||||
|
const url = 'http://localhost:8080'
|
||||||
|
let c
|
||||||
|
try {
|
||||||
|
c = createClient({ ...options, url })
|
||||||
|
console.info('[graphql] using local client')
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
c = createClient(options)
|
||||||
|
console.info(
|
||||||
|
`[graphql] using ${options.url.replace('https://', '').replace('/graphql', '').replace('/', '')}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
export const initClient = (options) => {
|
||||||
|
try {
|
||||||
|
if (isDev) {
|
||||||
|
console.info('[graphql] devmode detected')
|
||||||
|
return localClient(options)
|
||||||
|
} else return createClient(options)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
return localClient(options)
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,7 +32,7 @@ const options: ClientOptions = {
|
||||||
// меняем через setToken, например при получении значения с сервера
|
// меняем через setToken, например при получении значения с сервера
|
||||||
// скорее всего придумаем что-нибудь получше со временем
|
// скорее всего придумаем что-нибудь получше со временем
|
||||||
const token = localStorage.getItem(TOKEN_LOCAL_STORAGE_KEY)
|
const token = localStorage.getItem(TOKEN_LOCAL_STORAGE_KEY)
|
||||||
const headers = { Auth: token }
|
const headers = { Authorization: token }
|
||||||
return { headers }
|
return { headers }
|
||||||
},
|
},
|
||||||
exchanges
|
exchanges
|
||||||
|
|
|
@ -32,8 +32,8 @@ export default gql`
|
||||||
createdAt
|
createdAt
|
||||||
publishedAt
|
publishedAt
|
||||||
stat {
|
stat {
|
||||||
_id: viewed
|
# _id: viewed
|
||||||
viewed
|
# viewed
|
||||||
reacted
|
reacted
|
||||||
rating
|
rating
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,6 @@ export default gql`
|
||||||
body
|
body
|
||||||
slug
|
slug
|
||||||
pic
|
pic
|
||||||
parents
|
|
||||||
children
|
|
||||||
# community
|
# community
|
||||||
stat {
|
stat {
|
||||||
_id: shouts
|
_id: shouts
|
||||||
|
|
|
@ -13,8 +13,8 @@ export default gql`
|
||||||
_id: shouts
|
_id: shouts
|
||||||
shouts
|
shouts
|
||||||
authors
|
authors
|
||||||
# viewed
|
|
||||||
followers
|
followers
|
||||||
|
# viewed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ export default gql`
|
||||||
_id: shouts
|
_id: shouts
|
||||||
shouts
|
shouts
|
||||||
authors
|
authors
|
||||||
# viewed
|
|
||||||
followers
|
followers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ export default gql`
|
||||||
_id: shouts
|
_id: shouts
|
||||||
shouts
|
shouts
|
||||||
authors
|
authors
|
||||||
# viewed
|
|
||||||
followers
|
followers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ export default gql`
|
||||||
_id: shouts
|
_id: shouts
|
||||||
shouts
|
shouts
|
||||||
authors
|
authors
|
||||||
# viewed
|
|
||||||
followers
|
followers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -644,10 +644,8 @@ export type Token = {
|
||||||
|
|
||||||
export type Topic = {
|
export type Topic = {
|
||||||
body?: Maybe<Scalars['String']>
|
body?: Maybe<Scalars['String']>
|
||||||
children?: Maybe<Array<Maybe<Scalars['String']>>>
|
|
||||||
community: Community
|
community: Community
|
||||||
oid?: Maybe<Scalars['String']>
|
oid?: Maybe<Scalars['String']>
|
||||||
parents?: Maybe<Array<Maybe<Scalars['String']>>>
|
|
||||||
pic?: Maybe<Scalars['String']>
|
pic?: Maybe<Scalars['String']>
|
||||||
slug: Scalars['String']
|
slug: Scalars['String']
|
||||||
stat?: Maybe<TopicStat>
|
stat?: Maybe<TopicStat>
|
||||||
|
@ -656,9 +654,7 @@ export type Topic = {
|
||||||
|
|
||||||
export type TopicInput = {
|
export type TopicInput = {
|
||||||
body?: InputMaybe<Scalars['String']>
|
body?: InputMaybe<Scalars['String']>
|
||||||
children?: InputMaybe<Array<InputMaybe<Scalars['String']>>>
|
|
||||||
community: Scalars['String']
|
community: Scalars['String']
|
||||||
parents?: InputMaybe<Array<InputMaybe<Scalars['String']>>>
|
|
||||||
pic?: InputMaybe<Scalars['String']>
|
pic?: InputMaybe<Scalars['String']>
|
||||||
slug: Scalars['String']
|
slug: Scalars['String']
|
||||||
title?: InputMaybe<Scalars['String']>
|
title?: InputMaybe<Scalars['String']>
|
||||||
|
@ -671,7 +667,7 @@ export type TopicStat = {
|
||||||
rating?: Maybe<Scalars['Int']>
|
rating?: Maybe<Scalars['Int']>
|
||||||
reacted: Scalars['Int']
|
reacted: Scalars['Int']
|
||||||
shouts: Scalars['Int']
|
shouts: Scalars['Int']
|
||||||
viewed: Scalars['Int']
|
viewed?: Maybe<Scalars['Int']>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type User = {
|
export type User = {
|
||||||
|
|
|
@ -3,9 +3,9 @@ import Prerendered from '../main.astro'
|
||||||
import { Root } from '../components/Root'
|
import { Root } from '../components/Root'
|
||||||
import { apiClient } from '../utils/apiClient'
|
import { apiClient } from '../utils/apiClient'
|
||||||
import { initRouter } from '../stores/router'
|
import { initRouter } from '../stores/router'
|
||||||
import { PRERENDERED_ARTICLES_COUNT } from '../components/Views/Home'
|
import { PRERENDERED_ARTICLES_COUNT, RANDOM_TOPICS_COUNT } from '../components/Views/Home'
|
||||||
|
|
||||||
const randomTopics = await apiClient.getRandomTopics({ amount: 12 })
|
const randomTopics = await apiClient.getRandomTopics({ amount: RANDOM_TOPICS_COUNT })
|
||||||
const articles = await apiClient.getShouts(
|
const articles = await apiClient.getShouts(
|
||||||
{ filters: { visibility: "public" }, limit: PRERENDERED_ARTICLES_COUNT })
|
{ filters: { visibility: "public" }, limit: PRERENDERED_ARTICLES_COUNT })
|
||||||
|
|
||||||
|
|
|
@ -94,8 +94,8 @@ export const loadAllTopics = async (): Promise<void> => {
|
||||||
addTopics(topics)
|
addTopics(topics)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loadRandomTopics = async (): Promise<void> => {
|
export const loadRandomTopics = async ({ amount }: { amount: number }): Promise<void> => {
|
||||||
const topics = await apiClient.getRandomTopics({ amount: 12 })
|
const topics = await apiClient.getRandomTopics({ amount })
|
||||||
setRandomTopics(topics)
|
setRandomTopics(topics)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user