Merge remote-tracking branch 'origin/prepare-inbox' into prepare-inbox

This commit is contained in:
ilya-bkv 2022-11-24 18:39:43 +03:00
commit b46603c553
8 changed files with 16 additions and 18 deletions

View File

@ -1,5 +1,5 @@
overwrite: true overwrite: true
schema: 'https://testapi.discours.io' schema: 'http://localhost:8080'
generates: generates:
src/graphql/introspec.gen.ts: src/graphql/introspec.gen.ts:
plugins: plugins:

View File

@ -8,7 +8,7 @@ type SessionContextType = {
session: InitializedResource<AuthResult> session: InitializedResource<AuthResult>
isAuthenticated: Accessor<boolean> isAuthenticated: Accessor<boolean>
actions: { actions: {
refreshSession: () => AuthResult | Promise<AuthResult> getSession: () => AuthResult | Promise<AuthResult>
signIn: ({ email, password }: { email: string; password: string }) => Promise<void> signIn: ({ email, password }: { email: string; password: string }) => Promise<void>
signOut: () => Promise<void> signOut: () => Promise<void>
confirmEmail: (token: string) => Promise<void> confirmEmail: (token: string) => Promise<void>
@ -17,7 +17,7 @@ type SessionContextType = {
const SessionContext = createContext<SessionContextType>() const SessionContext = createContext<SessionContextType>()
const refreshSession = async (): Promise<AuthResult> => { const getSession = async (): Promise<AuthResult> => {
try { try {
const authResult = await apiClient.getSession() const authResult = await apiClient.getSession()
if (!authResult) { if (!authResult) {
@ -37,7 +37,7 @@ export function useSession() {
} }
export const SessionProvider = (props: { children: JSX.Element }) => { export const SessionProvider = (props: { children: JSX.Element }) => {
const [session, { refetch: refetchRefreshSession, mutate }] = createResource<AuthResult>(refreshSession, { const [session, { refetch: refetchSession, mutate }] = createResource<AuthResult>(getSession, {
ssrLoadFrom: 'initial', ssrLoadFrom: 'initial',
initialValue: null initialValue: null
}) })
@ -65,7 +65,7 @@ export const SessionProvider = (props: { children: JSX.Element }) => {
} }
const actions = { const actions = {
refreshSession: refetchRefreshSession, getSession: refetchSession,
signIn, signIn,
signOut, signOut,
confirmEmail confirmEmail
@ -74,7 +74,7 @@ export const SessionProvider = (props: { children: JSX.Element }) => {
const value: SessionContextType = { session, isAuthenticated, actions } const value: SessionContextType = { session, isAuthenticated, actions }
onMount(() => { onMount(() => {
refetchRefreshSession() refetchSession()
}) })
return <SessionContext.Provider value={value}>{props.children}</SessionContext.Provider> return <SessionContext.Provider value={value}>{props.children}</SessionContext.Provider>

View File

@ -1,8 +1,8 @@
import { gql } from '@urql/core' import { gql } from '@urql/core'
export default gql` export default gql`
mutation RefreshSessionMutation { mutation GetSessionMutation {
refreshSession { getSession {
error error
token token
user { user {

View File

@ -32,6 +32,7 @@ const options: ClientOptions = {
// меняем через setToken, например при получении значения с сервера // меняем через setToken, например при получении значения с сервера
// скорее всего придумаем что-нибудь получше со временем // скорее всего придумаем что-нибудь получше со временем
const token = localStorage.getItem(TOKEN_LOCAL_STORAGE_KEY) const token = localStorage.getItem(TOKEN_LOCAL_STORAGE_KEY)
if (token === null) alert('token is null')
const headers = { Authorization: token } const headers = { Authorization: token }
return { headers } return { headers }
}, },

View File

@ -176,11 +176,11 @@ export type Mutation = {
deleteShout: Result deleteShout: Result
destroyTopic: Result destroyTopic: Result
follow: Result follow: Result
getSession: AuthResult
inviteAuthor: Result inviteAuthor: Result
inviteChat: Result inviteChat: Result
markAsRead: Result markAsRead: Result
rateUser: Result rateUser: Result
refreshSession: AuthResult
registerUser: AuthResult registerUser: AuthResult
removeAuthor: Result removeAuthor: Result
sendLink: Result sendLink: Result
@ -661,10 +661,7 @@ export type TopicInput = {
export type TopicStat = { export type TopicStat = {
authors: Scalars['Int'] authors: Scalars['Int']
commented?: Maybe<Scalars['Int']>
followers: Scalars['Int'] followers: Scalars['Int']
rating?: Maybe<Scalars['Int']>
reacted: Scalars['Int']
shouts: Scalars['Int'] shouts: Scalars['Int']
} }

View File

@ -5,7 +5,7 @@ import { createPresignedPost } from '@aws-sdk/s3-presigned-post'
export default async function handler(req, res) { export default async function handler(req, res) {
const s3Client = new S3Client({ const s3Client = new S3Client({
region: process.env.S3_REGION, region: process.env.S3_REGION || 'eu-west-1',
credentials: { credentials: {
accessKeyId: process.env.S3_ACCESS_KEY, accessKeyId: process.env.S3_ACCESS_KEY,
secretAccessKey: process.env.S3_SECRET_KEY secretAccessKey: process.env.S3_SECRET_KEY
@ -13,7 +13,7 @@ export default async function handler(req, res) {
}) })
const post = await createPresignedPost(s3Client, { const post = await createPresignedPost(s3Client, {
Bucket: process.env.S3_BUCKET_NAME, Bucket: process.env.S3_BUCKET_NAME || 'discours-io',
Key: req.query.file, Key: req.query.file,
Fields: { Fields: {
acl: 'public-read', acl: 'public-read',

View File

@ -1,6 +1,6 @@
import { createStorageSignal } from '@solid-primitives/storage' import { createStorageSignal } from '@solid-primitives/storage'
// local stored seen marks by shout's slug // TODO: use indexedDB here
export const [seen, setSeen] = createStorageSignal<{ [slug: string]: Date }>('seen', {}) export const [seen, setSeen] = createStorageSignal<{ [slug: string]: Date }>('seen', {})
export const addSeen = (slug) => setSeen({ ...seen(), [slug]: Date.now() }) export const addSeen = (slug) => setSeen({ ...seen(), [slug]: Date.now() })

View File

@ -185,11 +185,11 @@ export const apiClient = {
throw new ApiError('unknown', response.error.message) throw new ApiError('unknown', response.error.message)
} }
if (response.data?.refreshSession?.error) { if (response.data?.getSession?.error) {
throw new ApiError('unknown', response.data.refreshSession.error) throw new ApiError('unknown', response.data.getSession.error)
} }
return response.data.refreshSession return response.data.getSession
}, },
getAllTopics: async () => { getAllTopics: async () => {
const response = await publicGraphQLClient.query(topicsAll, {}).toPromise() const response = await publicGraphQLClient.query(topicsAll, {}).toPromise()