diff --git a/codegen.yml b/codegen.yml index c5d2d3fa..2219d008 100644 --- a/codegen.yml +++ b/codegen.yml @@ -1,5 +1,5 @@ overwrite: true -schema: 'http://v2.discours.io/graphql' +schema: 'https://testapi.discours.io' generates: src/graphql/introspec.gen.ts: plugins: diff --git a/src/components/Pages/HomePage.tsx b/src/components/Pages/HomePage.tsx index 670374a2..2a22da3c 100644 --- a/src/components/Pages/HomePage.tsx +++ b/src/components/Pages/HomePage.tsx @@ -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 type { PageProps } from '../types' import { createSignal, onCleanup, onMount, Show } from 'solid-js' @@ -15,8 +15,8 @@ export const HomePage = (props: PageProps) => { return } - await loadShouts({ filters: { visibility: 'public' }, limit: PRERENDERED_ARTICLES_COUNT, offset: 0 }) - await loadRandomTopics() + await loadShouts({ filters: { visibility: 'public' }, limit: PRERENDERED_ARTICLES_COUNT }) + await loadRandomTopics({ amount: RANDOM_TOPICS_COUNT }) setIsLoaded(true) }) diff --git a/src/components/Views/Home.tsx b/src/components/Views/Home.tsx index 1378b453..c3520ef0 100644 --- a/src/components/Views/Home.tsx +++ b/src/components/Views/Home.tsx @@ -25,6 +25,7 @@ type HomeProps = { } export const PRERENDERED_ARTICLES_COUNT = 5 +export const RANDOM_TOPICS_COUNT = 12 const CLIENT_LOAD_ARTICLES_COUNT = 29 const LOAD_MORE_PAGE_SIZE = 16 // Row1 + Row3 + Row2 + Beside (3 + 1) + Row1 + Row 2 + Row3 diff --git a/src/graphql/cache.ts b/src/graphql/cache.ts index 69ebaa11..36132d2f 100644 --- a/src/graphql/cache.ts +++ b/src/graphql/cache.ts @@ -1,8 +1,10 @@ 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({ - // TODO: include introspection schema when needed keys: { Shout: (data) => data.slug, Author: (data) => data.slug, diff --git a/src/graphql/client.ts b/src/graphql/client.ts new file mode 100644 index 00000000..2c7a3e70 --- /dev/null +++ b/src/graphql/client.ts @@ -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) + } +} diff --git a/src/graphql/privateGraphQLClient.ts b/src/graphql/privateGraphQLClient.ts index 0beff1ec..c6863898 100644 --- a/src/graphql/privateGraphQLClient.ts +++ b/src/graphql/privateGraphQLClient.ts @@ -32,7 +32,7 @@ const options: ClientOptions = { // меняем через setToken, например при получении значения с сервера // скорее всего придумаем что-нибудь получше со временем const token = localStorage.getItem(TOKEN_LOCAL_STORAGE_KEY) - const headers = { Auth: token } + const headers = { Authorization: token } return { headers } }, exchanges diff --git a/src/graphql/query/articles-load.ts b/src/graphql/query/articles-load.ts index 276ef97e..32c45179 100644 --- a/src/graphql/query/articles-load.ts +++ b/src/graphql/query/articles-load.ts @@ -32,8 +32,8 @@ export default gql` createdAt publishedAt stat { - _id: viewed - viewed + # _id: viewed + # viewed reacted rating } diff --git a/src/graphql/query/topic-by-slug.ts b/src/graphql/query/topic-by-slug.ts index 0e440496..7ed25aa2 100644 --- a/src/graphql/query/topic-by-slug.ts +++ b/src/graphql/query/topic-by-slug.ts @@ -7,8 +7,6 @@ export default gql` body slug pic - parents - children # community stat { _id: shouts diff --git a/src/graphql/query/topics-all.ts b/src/graphql/query/topics-all.ts index e838f8e5..e20575f2 100644 --- a/src/graphql/query/topics-all.ts +++ b/src/graphql/query/topics-all.ts @@ -13,8 +13,8 @@ export default gql` _id: shouts shouts authors - # viewed followers + # viewed } } } diff --git a/src/graphql/query/topics-by-author.ts b/src/graphql/query/topics-by-author.ts index 90e7be5b..eaae45bc 100644 --- a/src/graphql/query/topics-by-author.ts +++ b/src/graphql/query/topics-by-author.ts @@ -12,7 +12,6 @@ export default gql` _id: shouts shouts authors - # viewed followers } } diff --git a/src/graphql/query/topics-by-community.ts b/src/graphql/query/topics-by-community.ts index 6545289e..32213a51 100644 --- a/src/graphql/query/topics-by-community.ts +++ b/src/graphql/query/topics-by-community.ts @@ -12,7 +12,6 @@ export default gql` _id: shouts shouts authors - # viewed followers } } diff --git a/src/graphql/query/topics-random.ts b/src/graphql/query/topics-random.ts index 2cf88e20..b85bf45c 100644 --- a/src/graphql/query/topics-random.ts +++ b/src/graphql/query/topics-random.ts @@ -13,7 +13,6 @@ export default gql` _id: shouts shouts authors - # viewed followers } } diff --git a/src/graphql/types.gen.ts b/src/graphql/types.gen.ts index 493f21a1..a57bc253 100644 --- a/src/graphql/types.gen.ts +++ b/src/graphql/types.gen.ts @@ -644,10 +644,8 @@ export type Token = { export type Topic = { body?: Maybe - children?: Maybe>> community: Community oid?: Maybe - parents?: Maybe>> pic?: Maybe slug: Scalars['String'] stat?: Maybe @@ -656,9 +654,7 @@ export type Topic = { export type TopicInput = { body?: InputMaybe - children?: InputMaybe>> community: Scalars['String'] - parents?: InputMaybe>> pic?: InputMaybe slug: Scalars['String'] title?: InputMaybe @@ -671,7 +667,7 @@ export type TopicStat = { rating?: Maybe reacted: Scalars['Int'] shouts: Scalars['Int'] - viewed: Scalars['Int'] + viewed?: Maybe } export type User = { diff --git a/src/pages/index.astro b/src/pages/index.astro index 929af43a..e659af95 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -3,9 +3,9 @@ import Prerendered from '../main.astro' import { Root } from '../components/Root' import { apiClient } from '../utils/apiClient' 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( { filters: { visibility: "public" }, limit: PRERENDERED_ARTICLES_COUNT }) diff --git a/src/stores/zine/topics.ts b/src/stores/zine/topics.ts index beaee83e..568695b0 100644 --- a/src/stores/zine/topics.ts +++ b/src/stores/zine/topics.ts @@ -94,8 +94,8 @@ export const loadAllTopics = async (): Promise => { addTopics(topics) } -export const loadRandomTopics = async (): Promise => { - const topics = await apiClient.getRandomTopics({ amount: 12 }) +export const loadRandomTopics = async ({ amount }: { amount: number }): Promise => { + const topics = await apiClient.getRandomTopics({ amount }) setRandomTopics(topics) }