diff --git a/codegen.yml b/codegen.yml index ec1872d9..85b46aa4 100644 --- a/codegen.yml +++ b/codegen.yml @@ -15,7 +15,7 @@ generates: # Generate types for core src/graphql/schema/core.gen.ts: - schema: 'https://testapi.discours.io' + schema: 'https://core.discours.io' plugins: - 'typescript' - 'typescript-operations' diff --git a/src/components/Nav/AuthModal/SocialProviders.tsx b/src/components/Nav/AuthModal/SocialProviders.tsx index f80f593c..c29f91ff 100644 --- a/src/components/Nav/AuthModal/SocialProviders.tsx +++ b/src/components/Nav/AuthModal/SocialProviders.tsx @@ -1,6 +1,5 @@ import { useLocalize } from '../../../context/localize' import { hideModal } from '../../../stores/ui' -import { apiBaseUrl } from '../../../utils/config' import { Icon } from '../../_shared/Icon' import styles from './SocialProviders.module.scss' @@ -10,7 +9,11 @@ type Provider = 'facebook' | 'google' | 'vk' | 'github' // 3rd party provider auth handler const handleSocialAuthLinkClick = (event: MouseEvent, provider: Provider): void => { event.preventDefault() - const popup = window.open(`${apiBaseUrl}/oauth/${provider}`, provider, 'width=740, height=420') + const popup = window.open( + `https://auth.discours.io/oauth_login/${provider}`, + provider, + 'width=740, height=420', + ) // TODO: precalculate window size popup?.focus() hideModal() } diff --git a/src/context/session.tsx b/src/context/session.tsx index fe28824f..fd800c52 100644 --- a/src/context/session.tsx +++ b/src/context/session.tsx @@ -6,12 +6,12 @@ import { VerifyEmailInput, LoginInput, AuthToken, User } from '@authorizerdev/au import { createContext, createMemo, createResource, createSignal, onMount, useContext } from 'solid-js' import { apiClient } from '../graphql/client/core' -import { getToken, resetToken } from '../graphql/privateGraphQLClient' import { showModal } from '../stores/ui' import { useAuthorizer } from './authorizer' import { useLocalize } from './localize' import { useSnackbar } from './snackbar' +import { cookieStorage, createStorage } from '@solid-primitives/storage' export type SessionContextType = { session: Resource @@ -52,7 +52,15 @@ export const SessionProvider = (props: { children: JSX.Element }) => { actions: { showSnackbar }, } = useSnackbar() const [, { authorizer }] = useAuthorizer() - const [authToken, setToken] = createSignal('') + // const [getToken, setToken] = createSignal('') + // https://start.solidjs.com/api/createCookieSessionStorage + const [store, setStore, { remove, clear, toJSON }] = createStorage({ + api: cookieStorage, + prefix: 'discoursio', + }) + const getToken = () => store.token + const setToken = (value) => setStore('token', value) + const resetToken = () => remove('token') const loadSubscriptions = async (): Promise => { const result = await apiClient.getMySubscriptions() diff --git a/src/graphql/client/core.ts b/src/graphql/client/core.ts index 5834b77e..82f7e1cf 100644 --- a/src/graphql/client/core.ts +++ b/src/graphql/client/core.ts @@ -10,6 +10,8 @@ import type { Shout, Result, QueryLoad_Authors_ByArgs, + QueryLoad_Shouts_SearchArgs, + QueryLoad_Shouts_ByArgs, } from '../schema/core.gen' import createArticle from '../mutation/core/article-create' @@ -25,6 +27,7 @@ import { getPrivateClient } from '../privateGraphQLClient' import { getPublicClient } from '../publicGraphQLClient' import shoutLoad from '../query/core/article-load' import shoutsLoadBy from '../query/core/articles-load-by' +import shoutsLoadSearch from '../query/core/articles-load-search' import draftsLoad from '../query/core/articles-load-drafts' import myFeed from '../query/core/articles-load-feed' import authorBy from '../query/core/author-by' @@ -176,8 +179,8 @@ export const apiClient = { return resp.data.get_shout }, - getShouts: async (options: LoadShoutsOptions) => { - const resp = await publicGraphQLClient.query(shoutsLoadBy, { options }).toPromise() + getShouts: async (args: QueryLoad_Shouts_ByArgs) => { + const resp = await publicGraphQLClient.query(shoutsLoadBy, args).toPromise() if (resp.error) { console.error(resp) } @@ -185,8 +188,17 @@ export const apiClient = { return resp.data.load_shouts_by }, - getMyFeed: async (options: LoadShoutsOptions) => { - const resp = await privateGraphQLClient.query(myFeed, { options }).toPromise() + getShoutsSearch: async (args: QueryLoad_Shouts_SearchArgs) => { + const resp = await publicGraphQLClient.query(shoutsLoadSearch, args).toPromise() + if (resp.error) { + console.error(resp) + } + + return resp.data.load_shouts_search + }, + + getMyFeed: async (args: QueryLoad_Shouts_ByArgs) => { + const resp = await privateGraphQLClient.query(myFeed, args).toPromise() if (resp.error) { console.error(resp) diff --git a/src/graphql/query/core/articles-load-search.ts b/src/graphql/query/core/articles-load-search.ts new file mode 100644 index 00000000..14bd825d --- /dev/null +++ b/src/graphql/query/core/articles-load-search.ts @@ -0,0 +1,34 @@ +import { gql } from '@urql/core' + +export default gql` + query MyFeedQuery($options: LoadShoutsOptions) { + load_shouts_search(options: $options) { + id + title + subtitle + slug + layout + cover + topics { + id + title + body + slug + } + authors { + id + name + slug + pic + created_at + } + created_at + published_at + stat { + viewed + reacted + rating + } + } + } +` diff --git a/src/pages/author.page.server.ts b/src/pages/author.page.server.ts index 42d9a247..42f1e30d 100644 --- a/src/pages/author.page.server.ts +++ b/src/pages/author.page.server.ts @@ -14,12 +14,11 @@ export const onBeforeRender = async (pageContext: PageContext) => { if (!author) { throw render(404) } - - const authorShouts = await apiClient.getShouts({ + const options = { filters: { author: slug, visibility: 'community' }, limit: PRERENDERED_ARTICLES_COUNT, - }) - + } + const authorShouts = await apiClient.getShouts({ options }) const pageProps: PageProps = { author, authorShouts, seo: { title: author.name } } return { diff --git a/src/pages/expo/expo.page.server.ts b/src/pages/expo/expo.page.server.ts index 0303c533..0df7d84b 100644 --- a/src/pages/expo/expo.page.server.ts +++ b/src/pages/expo/expo.page.server.ts @@ -5,10 +5,11 @@ import { PRERENDERED_ARTICLES_COUNT } from '../../components/Views/Expo/Expo' import { apiClient } from '../../graphql/client/core' export const onBeforeRender = async (_pageContext: PageContext) => { - const expoShouts = await apiClient.getShouts({ + const options = { filters: { layouts: ['audio', 'video', 'literature', 'image'] }, limit: PRERENDERED_ARTICLES_COUNT, - }) + } + const expoShouts = await apiClient.getShouts({ options }) const pageProps: PageProps = { expoShouts, seo: { title: '' } } return { pageContext: { diff --git a/src/pages/expo/expoLayout.page.server.ts b/src/pages/expo/expoLayout.page.server.ts index 00f8e440..c19f26c8 100644 --- a/src/pages/expo/expoLayout.page.server.ts +++ b/src/pages/expo/expoLayout.page.server.ts @@ -6,11 +6,11 @@ import { apiClient } from '../../graphql/client/core' export const onBeforeRender = async (pageContext: PageContext) => { const { layout } = pageContext.routeParams - const expoShouts = await apiClient.getShouts({ + const options = { filters: { layouts: [layout] }, limit: PRERENDERED_ARTICLES_COUNT, - }) - + } + const expoShouts = await apiClient.getShouts({ options }) const pageProps: PageProps = { expoShouts, seo: { title: '' } } return { diff --git a/src/pages/index.page.server.ts b/src/pages/index.page.server.ts index 091d4c8a..faa79d5f 100644 --- a/src/pages/index.page.server.ts +++ b/src/pages/index.page.server.ts @@ -5,11 +5,11 @@ import { PRERENDERED_ARTICLES_COUNT } from '../components/Views/Home' import { apiClient } from '../graphql/client/core' export const onBeforeRender = async (_pageContext: PageContext) => { - const homeShouts = await apiClient.getShouts({ + const options = { filters: { visibility: 'public' }, limit: PRERENDERED_ARTICLES_COUNT, - }) - + } + const homeShouts = await apiClient.getShouts({ options }) const pageProps: PageProps = { homeShouts, seo: { title: '' } } return { diff --git a/src/pages/search.page.server.ts b/src/pages/search.page.server.ts index 418f9380..05b987ed 100644 --- a/src/pages/search.page.server.ts +++ b/src/pages/search.page.server.ts @@ -6,7 +6,7 @@ import { apiClient } from '../graphql/client/core' export const onBeforeRender = async (pageContext: PageContext) => { const { q } = pageContext.routeParams - const searchResults = await apiClient.getShouts({ filters: { title: q, body: q }, limit: 50 }) + const searchResults = await apiClient.getShoutsSearch({ text: q, limit: 50 }) const pageProps: PageProps = { searchResults, seo: { title: '' } } diff --git a/src/stores/zine/articles.ts b/src/stores/zine/articles.ts index e3994188..2bbd530e 100644 --- a/src/stores/zine/articles.ts +++ b/src/stores/zine/articles.ts @@ -137,12 +137,9 @@ export const loadShout = async (slug: string): Promise => { export const loadShouts = async ( options: LoadShoutsOptions, ): Promise<{ hasMore: boolean; newShouts: Shout[] }> => { - const newShouts = await apiClient.getShouts({ - ...options, - limit: options.limit + 1, - }) - - const hasMore = newShouts.length === options.limit + 1 + options.limit += 1 + const newShouts = await apiClient.getShouts({ options }) + const hasMore = newShouts ?? newShouts.length === options.limit + 1 if (hasMore) { newShouts.splice(-1) @@ -157,12 +154,9 @@ export const loadShouts = async ( export const loadMyFeed = async ( options: LoadShoutsOptions, ): Promise<{ hasMore: boolean; newShouts: Shout[] }> => { - const newShouts = await apiClient.getMyFeed({ - ...options, - limit: options.limit + 1, - }) - - const hasMore = newShouts.length === options.limit + 1 + options.limit += 1 + const newShouts = await apiClient.getMyFeed({ options }) + const hasMore = newShouts ?? newShouts.length === options.limit + 1 if (hasMore) { newShouts.splice(-1) @@ -193,15 +187,17 @@ type InitialState = { const TOP_MONTH_ARTICLES_COUNT = 10 export const loadTopMonthArticles = async (): Promise => { - const articles = await apiClient.getShouts({ + const daysago = Date.now() - 30 * 24 * 60 * 60 * 1000 + const after = Math.floor(daysago / 1000) + const options: LoadShoutsOptions = { filters: { visibility: 'public', - // TODO: replace with from, to - time_ago: 30 * 24 * 60 * 60 * 1000, + after, }, order_by: 'rating_stat', limit: TOP_MONTH_ARTICLES_COUNT, - }) + } + const articles = await apiClient.getShouts({ options }) addArticles(articles) setTopMonthArticles(articles) } @@ -209,13 +205,14 @@ export const loadTopMonthArticles = async (): Promise => { const TOP_ARTICLES_COUNT = 10 export const loadTopArticles = async (): Promise => { - const articles = await apiClient.getShouts({ + const options: LoadShoutsOptions = { filters: { visibility: 'public', }, order_by: 'rating_stat', limit: TOP_ARTICLES_COUNT, - }) + } + const articles = await apiClient.getShouts({ options }) addArticles(articles) setTopArticles(articles) } diff --git a/src/stores/zine/layouts.ts b/src/stores/zine/layouts.ts index 6496e5b1..33e1f622 100644 --- a/src/stores/zine/layouts.ts +++ b/src/stores/zine/layouts.ts @@ -27,11 +27,8 @@ export const resetSortedLayoutShouts = () => { } export const loadLayoutShoutsBy = async (options: LoadShoutsOptions): Promise<{ hasMore: boolean }> => { - const newLayoutShouts = await apiClient.getShouts({ - ...options, - limit: options.limit + 1, - }) - + options.limit += 1 + const newLayoutShouts = await apiClient.getShouts({ options }) const hasMore = newLayoutShouts.length === options.limit + 1 if (hasMore) { diff --git a/src/utils/handleFileUpload.ts b/src/utils/handleFileUpload.ts index af2df1da..7013de52 100644 --- a/src/utils/handleFileUpload.ts +++ b/src/utils/handleFileUpload.ts @@ -2,8 +2,7 @@ import { UploadFile } from '@solid-primitives/upload' import { UploadedFile } from '../pages/types' -import { apiBaseUrl } from './config' - +const apiBaseUrl = 'https://core.discours.io' const apiUrl = `${apiBaseUrl}/upload` export const handleFileUpload = async (uploadFile: UploadFile): Promise => {