From 57baccccf2716626c8b0bf737a8b3ac09a4142ff Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 18 Dec 2023 04:15:49 +0300 Subject: [PATCH] merged. --- src/components/Views/Author/Author.tsx | 4 +- src/components/Views/Expo/Expo.tsx | 42 +++++++++---------- src/components/Views/Feed/Feed.tsx | 4 +- src/components/Views/Feed/index.ts | 2 +- src/graphql/client/core.ts | 21 ++++++++++ src/graphql/graphQLClient.ts | 0 .../query/core/articles-load-followed.ts | 2 +- .../{ => core}/articles-load-random-top.ts | 17 ++++---- .../query/{ => core}/articles-load-unrated.ts | 14 +++---- src/graphql/types.gen.ts | 0 src/pages/expo/expoLayout.page.server.ts | 0 src/utils/apiClient.ts | 0 src/utils/getServerDate.ts | 4 ++ src/utils/meta.ts | 2 +- 14 files changed, 66 insertions(+), 46 deletions(-) delete mode 100644 src/graphql/graphQLClient.ts rename src/graphql/query/{ => core}/articles-load-random-top.ts (76%) rename src/graphql/query/{ => core}/articles-load-unrated.ts (83%) delete mode 100644 src/graphql/types.gen.ts delete mode 100644 src/pages/expo/expoLayout.page.server.ts delete mode 100644 src/utils/apiClient.ts diff --git a/src/components/Views/Author/Author.tsx b/src/components/Views/Author/Author.tsx index f1b494f6..3d29ba44 100644 --- a/src/components/Views/Author/Author.tsx +++ b/src/components/Views/Author/Author.tsx @@ -130,8 +130,8 @@ export const AuthorView = (props: Props) => { } }) - const ogImage = props.author?.userpic - ? getImageUrl(props.author.userpic, { width: 1200 }) + const ogImage = props.author?.pic + ? getImageUrl(props.author.pic, { width: 1200 }) : getImageUrl('production/image/logo_image.png') const description = getDescription(props.author?.bio) const ogTitle = props.author?.name diff --git a/src/components/Views/Expo/Expo.tsx b/src/components/Views/Expo/Expo.tsx index 22f4bb9b..8127dcad 100644 --- a/src/components/Views/Expo/Expo.tsx +++ b/src/components/Views/Expo/Expo.tsx @@ -3,17 +3,12 @@ import { clsx } from 'clsx' import { createEffect, createMemo, createSignal, For, on, onCleanup, onMount, Show } from 'solid-js' import { useLocalize } from '../../../context/localize' -import { - LoadRandomTopShoutsParams, - LoadShoutsFilters, - LoadShoutsOptions, - Shout, -} from '../../../graphql/schema/core.gen' +import { apiClient } from '../../../graphql/client/core' +import { LoadShoutsFilters, LoadShoutsOptions, Shout } from '../../../graphql/schema/core.gen' import { LayoutType } from '../../../pages/types' import { router } from '../../../stores/router' import { loadShouts, resetSortedArticles, useArticlesStore } from '../../../stores/zine/articles' -import { apiClient } from '../../../utils/apiClient' -import { getServerDate } from '../../../utils/getServerDate' +import { getUnixtime } from '../../../utils/getServerDate' import { restoreScrollPosition, saveScrollPosition } from '../../../utils/scroll' import { splitToPages } from '../../../utils/splitToPages' import { Button } from '../../_shared/Button' @@ -48,10 +43,11 @@ export const Expo = (props: Props) => { const getLoadShoutsFilters = (filters: LoadShoutsFilters = {}): LoadShoutsFilters => { const result = { ...filters } + filters.layouts = [] if (props.layout) { - filters.layout = props.layout + filters.layouts.push(props.layout) } else { - filters.excludeLayout = 'article' + filters.layouts.push('article') } return result @@ -64,8 +60,8 @@ export const Expo = (props: Props) => { offset: sortedArticles().length, } - options.filters = getLayout() - ? { layouts: [getLayout()] } + options.filters = props.layout + ? { layouts: [props.layout] } : { layouts: ['audio', 'video', 'image', 'literature'] } const { hasMore } = await loadShouts(options) @@ -79,27 +75,27 @@ export const Expo = (props: Props) => { } const loadRandomTopArticles = async () => { - const params: LoadRandomTopShoutsParams = { + const options: LoadShoutsOptions = { filters: getLoadShoutsFilters(), limit: 10, - fromRandomCount: 100, + random_limit: 100, } - const result = await apiClient.getRandomTopShouts(params) + const result = await apiClient.getRandomTopShouts({ options }) setRandomTopArticles(result) } const loadRandomTopMonthArticles = async () => { const now = new Date() - const fromDate = getServerDate(new Date(now.setMonth(now.getMonth() - 1))) + const after = getUnixtime(new Date(now.setMonth(now.getMonth() - 1))) - const params: LoadRandomTopShoutsParams = { - filters: getLoadShoutsFilters({ fromDate }), + const options: LoadShoutsOptions = { + filters: getLoadShoutsFilters({ after }), limit: 10, - fromRandomCount: 10, + random_limit: 10, } - const result = await apiClient.getRandomTopShouts(params) + const result = await apiClient.getRandomTopShouts({ options }) setRandomTopMonthArticles(result) } @@ -171,11 +167,11 @@ export const Expo = (props: Props) => { {t('Literature')} -
  • +
  • ( - {children} + {children} )} > {t('Music')} diff --git a/src/components/Views/Feed/Feed.tsx b/src/components/Views/Feed/Feed.tsx index 5199977a..ba63b7fd 100644 --- a/src/components/Views/Feed/Feed.tsx +++ b/src/components/Views/Feed/Feed.tsx @@ -1,4 +1,4 @@ -import type { Author, LoadShoutsOptions, Reaction, Shout } from '../../graphql/schema/core.gen' +import type { Author, LoadShoutsOptions, Reaction, Shout } from '../../../graphql/schema/core.gen' import { getPagePath } from '@nanostores/router' import { Meta } from '@solidjs/meta' @@ -7,11 +7,11 @@ import { createEffect, createSignal, For, on, onMount, Show } from 'solid-js' import { useLocalize } from '../../../context/localize' import { useReactions } from '../../../context/reactions' +import { apiClient } from '../../../graphql/client/core' import { router, useRouter } from '../../../stores/router' import { useArticlesStore, resetSortedArticles } from '../../../stores/zine/articles' import { useTopAuthorsStore } from '../../../stores/zine/topAuthors' import { useTopicsStore } from '../../../stores/zine/topics' -import { apiClient } from '../../../utils/apiClient' import { getImageUrl } from '../../../utils/getImageUrl' import { Icon } from '../../_shared/Icon' import { Loading } from '../../_shared/Loading' diff --git a/src/components/Views/Feed/index.ts b/src/components/Views/Feed/index.ts index f0fa7232..4595b5cc 100644 --- a/src/components/Views/Feed/index.ts +++ b/src/components/Views/Feed/index.ts @@ -1 +1 @@ -export { Feed } from './Feed' +export { FeedView as Feed } from './Feed' diff --git a/src/graphql/client/core.ts b/src/graphql/client/core.ts index b02b08e2..6b544a9f 100644 --- a/src/graphql/client/core.ts +++ b/src/graphql/client/core.ts @@ -11,6 +11,7 @@ import type { Result, QueryLoad_Authors_ByArgs, QueryLoad_Shouts_SearchArgs, + QueryLoad_Shouts_Random_TopArgs, } from '../schema/core.gen' import { createGraphQLClient } from '../createGraphQLClient' @@ -27,7 +28,9 @@ import shoutLoad from '../query/core/article-load' import shoutsLoadBy from '../query/core/articles-load-by' import draftsLoad from '../query/core/articles-load-drafts' import myFeed from '../query/core/articles-load-feed' +import loadShoutsTopRandom from '../query/core/articles-load-random-top' import shoutsLoadSearch from '../query/core/articles-load-search' +import loadShoutsUnrated from '../query/core/articles-load-unrated' import authorBy from '../query/core/author-by' import authorFollowers from '../query/core/author-followers' import authorId from '../query/core/author-id' @@ -47,6 +50,24 @@ export const apiClient = { private: null, connect: (token: string) => (apiClient.private = createGraphQLClient('core', token)), // NOTE: use it after token appears + getRandomTopShouts: async (params: QueryLoad_Shouts_Random_TopArgs) => { + const response = await publicGraphQLClient.query(loadShoutsTopRandom, params).toPromise() + if (!response.data) { + console.error('[graphql.core] getRandomTopShouts error', response.error) + } + return response.data.load_shouts_top_random + }, + + getUnratedShouts: async (limit = 50, offset = 0) => { + const response = await apiClient.private.query(loadShoutsUnrated, { limit, offset }).toPromise() + + if (!response.data) { + console.error('[graphql.core] getUnratedShouts error', response.error) + } + + return response.data.load_shouts_unrated + }, + getRandomTopics: async ({ amount }: { amount: number }) => { const response = await publicGraphQLClient.query(topicsRandomQuery, { amount }).toPromise() diff --git a/src/graphql/graphQLClient.ts b/src/graphql/graphQLClient.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/src/graphql/query/core/articles-load-followed.ts b/src/graphql/query/core/articles-load-followed.ts index 25260637..122f290b 100644 --- a/src/graphql/query/core/articles-load-followed.ts +++ b/src/graphql/query/core/articles-load-followed.ts @@ -8,7 +8,7 @@ export default gql` layout slug cover - # community + # cover_caption main_topic topics { # id diff --git a/src/graphql/query/articles-load-random-top.ts b/src/graphql/query/core/articles-load-random-top.ts similarity index 76% rename from src/graphql/query/articles-load-random-top.ts rename to src/graphql/query/core/articles-load-random-top.ts index 9ac58789..20e32b27 100644 --- a/src/graphql/query/articles-load-random-top.ts +++ b/src/graphql/query/core/articles-load-random-top.ts @@ -2,18 +2,17 @@ import { gql } from '@urql/core' export default gql` query LoadRandomTopShoutsQuery($params: LoadRandomTopShoutsParams) { - loadRandomTopShouts(params: $params) { + load_shouts_top_random(params: $params) { id title - lead + # lead description subtitle slug layout cover - lead - # community - mainTopic + cover_caption + main_topic topics { id title @@ -29,12 +28,12 @@ export default gql` id name slug - userpic - createdAt + pic + created_at bio } - createdAt - publishedAt + created_at + published_at stat { viewed reacted diff --git a/src/graphql/query/articles-load-unrated.ts b/src/graphql/query/core/articles-load-unrated.ts similarity index 83% rename from src/graphql/query/articles-load-unrated.ts rename to src/graphql/query/core/articles-load-unrated.ts index 36d00301..a4d01b66 100644 --- a/src/graphql/query/articles-load-unrated.ts +++ b/src/graphql/query/core/articles-load-unrated.ts @@ -5,15 +5,15 @@ export default gql` loadUnratedShouts(limit: $limit) { id title - lead + # lead description subtitle slug layout cover - lead + cover_caption # community - mainTopic + main_topic topics { id title @@ -29,12 +29,12 @@ export default gql` id name slug - userpic - createdAt + pic + created_at bio } - createdAt - publishedAt + created_at + published_at stat { viewed reacted diff --git a/src/graphql/types.gen.ts b/src/graphql/types.gen.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/src/pages/expo/expoLayout.page.server.ts b/src/pages/expo/expoLayout.page.server.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/src/utils/apiClient.ts b/src/utils/apiClient.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/src/utils/getServerDate.ts b/src/utils/getServerDate.ts index feea507c..39fa4223 100644 --- a/src/utils/getServerDate.ts +++ b/src/utils/getServerDate.ts @@ -2,3 +2,7 @@ export const getServerDate = (date: Date): string => { // 2023-12-31 return date.toISOString().slice(0, 10) } + +export const getUnixtime = (date: Date): number => { + return Math.floor(date.getTime() / 1000) +} diff --git a/src/utils/meta.ts b/src/utils/meta.ts index b536e9da..f998977e 100644 --- a/src/utils/meta.ts +++ b/src/utils/meta.ts @@ -1,4 +1,4 @@ -import { Shout } from '../graphql/types.gen' +import { Shout } from '../graphql/schema/core.gen' const MAX_DESCRIPTION_LENGTH = 150 export const getDescription = (body: string): string => {