From 5f592e6fff90b88480f9cc29d47ffbc5b08d55d5 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 25 Jan 2024 21:19:59 +0300 Subject: [PATCH] postmerge-fix --- .../Author/AuthorBadge/AuthorBadge.tsx | 2 +- .../Nav/SearchModal/SearchModal.tsx | 24 +- .../Nav/SearchModal/SearchResultItem.tsx | 4 +- src/context/reactions.tsx | 10 +- src/graphql/types.gen.ts | 726 ------------------ src/stores/zine/authors.ts | 2 +- src/utils/apiClient.ts | 31 - 7 files changed, 25 insertions(+), 774 deletions(-) delete mode 100644 src/graphql/types.gen.ts delete mode 100644 src/utils/apiClient.ts diff --git a/src/components/Author/AuthorBadge/AuthorBadge.tsx b/src/components/Author/AuthorBadge/AuthorBadge.tsx index 64a6275b..a596075a 100644 --- a/src/components/Author/AuthorBadge/AuthorBadge.tsx +++ b/src/components/Author/AuthorBadge/AuthorBadge.tsx @@ -1,4 +1,4 @@ -import { getPagePath, openPage } from '@nanostores/router' +import { openPage } from '@nanostores/router' import { clsx } from 'clsx' import { createEffect, createMemo, createSignal, Match, Show, Switch } from 'solid-js' diff --git a/src/components/Nav/SearchModal/SearchModal.tsx b/src/components/Nav/SearchModal/SearchModal.tsx index 5bcb3e50..a0295f5f 100644 --- a/src/components/Nav/SearchModal/SearchModal.tsx +++ b/src/components/Nav/SearchModal/SearchModal.tsx @@ -1,13 +1,14 @@ -import { createSignal, Show, For } from 'solid-js' - -import { Button } from '../../_shared/Button' -import { Icon } from '../../_shared/Icon' -import { SearchResultItem } from './SearchResultItem' - -import { apiClient } from '../../../utils/apiClient' import type { Shout } from '../../../graphql/schema/core.gen' +import { createSignal, Show, For } from 'solid-js' + import { useLocalize } from '../../../context/localize' +import { apiClient } from '../../../graphql/client/core' +import { Button } from '../../_shared/Button' +import { Icon } from '../../_shared/Icon' +import { FEED_PAGE_SIZE } from '../../Views/Feed/Feed' + +import { SearchResultItem } from './SearchResultItem' import styles from './SearchModal.module.scss' @@ -16,7 +17,7 @@ import styles from './SearchModal.module.scss' // @@TODO implement FILTERS & TOPICS const getSearchCoincidences = ({ str, intersection }: { str: string; intersection: string }) => - `${str.replace( + `${str.replaceAll( new RegExp(intersection, 'gi'), (casePreservedMatch) => `${casePreservedMatch}`, )}` @@ -60,7 +61,12 @@ export const SearchModal = () => { setIsLoading(true) try { - const response = await apiClient.getSearchResults(searchValue) + // TODO: use offset to load more + const response = await apiClient.getShoutsSearch({ + text: searchValue, + limit: FEED_PAGE_SIZE, + offset: 0, + }) const searchResult = await response.json() if (searchResult.length > 0) { diff --git a/src/components/Nav/SearchModal/SearchResultItem.tsx b/src/components/Nav/SearchModal/SearchResultItem.tsx index b4b0fbb0..948e37de 100644 --- a/src/components/Nav/SearchModal/SearchResultItem.tsx +++ b/src/components/Nav/SearchModal/SearchResultItem.tsx @@ -1,7 +1,7 @@ -import { ArticleCard } from '../../Feed/ArticleCard' - import type { Shout } from '../../../graphql/schema/core.gen' +import { ArticleCard } from '../../Feed/ArticleCard' + interface SearchCardProps { settings?: { noicon?: boolean diff --git a/src/context/reactions.tsx b/src/context/reactions.tsx index 8717f6da..c98ebcaa 100644 --- a/src/context/reactions.tsx +++ b/src/context/reactions.tsx @@ -82,10 +82,12 @@ export const ReactionsProvider = (props: { children: JSX.Element }) => { } const deleteReaction = async (reaction_id: number): Promise => { - const r = await apiClient.destroyReaction(reaction_id) - setReactionEntities({ - [reaction_id]: undefined, - }) + if (reaction_id) { + await apiClient.destroyReaction(reaction_id) + setReactionEntities({ + [reaction_id]: undefined, + }) + } } const updateReaction = async (id: number, input: ReactionInput): Promise => { diff --git a/src/graphql/types.gen.ts b/src/graphql/types.gen.ts deleted file mode 100644 index 60674764..00000000 --- a/src/graphql/types.gen.ts +++ /dev/null @@ -1,726 +0,0 @@ -import gql from 'graphql-tag' -export type Maybe = T | null -export type InputMaybe = Maybe -export type Exact = { [K in keyof T]: T[K] } -export type MakeOptional = Omit & { [SubKey in K]?: Maybe } -export type MakeMaybe = Omit & { [SubKey in K]: Maybe } -export type MakeEmpty = { [_ in K]?: never } -export type Incremental = - | T - | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never } -/** All built-in and custom scalars, mapped to their actual values */ -export type Scalars = { - ID: { input: string; output: string } - String: { input: string; output: string } - Boolean: { input: boolean; output: boolean } - Int: { input: number; output: number } - Float: { input: number; output: number } - DateTime: { input: any; output: any } -} - -export type AuthResult = { - error?: Maybe - token?: Maybe - user?: Maybe -} - -export type Author = { - about?: Maybe - bio?: Maybe - caption?: Maybe - createdAt?: Maybe - id: Scalars['Int']['output'] - lastSeen?: Maybe - links?: Maybe>> - name: Scalars['String']['output'] - roles?: Maybe>> - slug: Scalars['String']['output'] - stat?: Maybe - userpic?: Maybe -} - -export type AuthorStat = { - commented?: Maybe - followers?: Maybe - followings?: Maybe - rating?: Maybe - shouts?: Maybe -} - -export type AuthorsBy = { - createdAt?: InputMaybe - days?: InputMaybe - lastSeen?: InputMaybe - name?: InputMaybe - order?: InputMaybe - slug?: InputMaybe - stat?: InputMaybe - topic?: InputMaybe -} - -export type Chat = { - admins?: Maybe>> - createdAt: Scalars['Int']['output'] - createdBy: Scalars['Int']['output'] - description?: Maybe - id: Scalars['String']['output'] - members?: Maybe>> - messages?: Maybe>> - private?: Maybe - title?: Maybe - unread?: Maybe - updatedAt: Scalars['Int']['output'] - users?: Maybe>> -} - -export type ChatInput = { - description?: InputMaybe - id: Scalars['String']['input'] - title?: InputMaybe -} - -export type ChatMember = { - id: Scalars['Int']['output'] - lastSeen?: Maybe - name: Scalars['String']['output'] - online?: Maybe - slug: Scalars['String']['output'] - userpic?: Maybe -} - -export type Collection = { - amount?: Maybe - createdAt: Scalars['DateTime']['output'] - createdBy: User - desc?: Maybe - id: Scalars['Int']['output'] - publishedAt?: Maybe - slug: Scalars['String']['output'] - title: Scalars['String']['output'] -} - -export type Community = { - createdAt: Scalars['DateTime']['output'] - createdBy: User - desc?: Maybe - id: Scalars['Int']['output'] - name: Scalars['String']['output'] - pic: Scalars['String']['output'] - slug: Scalars['String']['output'] -} - -export enum FollowingEntity { - Author = 'AUTHOR', - Community = 'COMMUNITY', - Reactions = 'REACTIONS', - Topic = 'TOPIC', -} - -export type LoadRandomTopShoutsParams = { - filters?: InputMaybe - fromRandomCount?: InputMaybe - limit: Scalars['Int']['input'] -} - -export type LoadShoutsFilters = { - author?: InputMaybe - excludeLayout?: InputMaybe - fromDate?: InputMaybe - layout?: InputMaybe - reacted?: InputMaybe - toDate?: InputMaybe - topic?: InputMaybe - visibility?: InputMaybe -} - -export type LoadShoutsOptions = { - filters?: InputMaybe - limit: Scalars['Int']['input'] - offset?: InputMaybe - order_by?: InputMaybe - order_by_desc?: InputMaybe - with_author_captions?: InputMaybe -} - -export type Message = { - author: Scalars['Int']['output'] - body: Scalars['String']['output'] - chatId: Scalars['String']['output'] - createdAt: Scalars['Int']['output'] - id: Scalars['Int']['output'] - replyTo?: Maybe - seen?: Maybe - updatedAt?: Maybe -} - -export enum MessageStatus { - Deleted = 'DELETED', - New = 'NEW', - Updated = 'UPDATED', -} - -export type MessagesBy = { - author?: InputMaybe - body?: InputMaybe - chat?: InputMaybe - days?: InputMaybe - order?: InputMaybe - stat?: InputMaybe -} - -export type Mutation = { - confirmEmail: AuthResult - createChat: Result - createMessage: Result - createReaction: Result - createShout: Result - createTopic: Result - deleteChat: Result - deleteMessage: Result - deleteReaction: Result - deleteShout: Result - destroyTopic: Result - follow: Result - getSession: AuthResult - markAllNotificationsAsRead: Result - markAsRead: Result - markNotificationAsRead: Result - rateUser: Result - registerUser: AuthResult - sendLink: Result - unfollow: Result - updateChat: Result - updateMessage: Result - updateProfile: Result - updateReaction: Result - updateShout: Result - updateTopic: Result -} - -export type MutationConfirmEmailArgs = { - token: Scalars['String']['input'] -} - -export type MutationCreateChatArgs = { - members: Array> - title?: InputMaybe -} - -export type MutationCreateMessageArgs = { - body: Scalars['String']['input'] - chat: Scalars['String']['input'] - replyTo?: InputMaybe -} - -export type MutationCreateReactionArgs = { - reaction: ReactionInput -} - -export type MutationCreateShoutArgs = { - inp: ShoutInput -} - -export type MutationCreateTopicArgs = { - input: TopicInput -} - -export type MutationDeleteChatArgs = { - chatId: Scalars['String']['input'] -} - -export type MutationDeleteMessageArgs = { - chatId: Scalars['String']['input'] - id: Scalars['Int']['input'] -} - -export type MutationDeleteReactionArgs = { - id: Scalars['Int']['input'] -} - -export type MutationDeleteShoutArgs = { - shout_id: Scalars['Int']['input'] -} - -export type MutationDestroyTopicArgs = { - slug: Scalars['String']['input'] -} - -export type MutationFollowArgs = { - slug: Scalars['String']['input'] - what: FollowingEntity -} - -export type MutationMarkAsReadArgs = { - chatId: Scalars['String']['input'] - ids: Array> -} - -export type MutationMarkNotificationAsReadArgs = { - notification_id: Scalars['Int']['input'] -} - -export type MutationRateUserArgs = { - slug: Scalars['String']['input'] - value: Scalars['Int']['input'] -} - -export type MutationRegisterUserArgs = { - email: Scalars['String']['input'] - name?: InputMaybe - password?: InputMaybe -} - -export type MutationSendLinkArgs = { - email: Scalars['String']['input'] - lang?: InputMaybe - template?: InputMaybe -} - -export type MutationUnfollowArgs = { - slug: Scalars['String']['input'] - what: FollowingEntity -} - -export type MutationUpdateChatArgs = { - chat: ChatInput -} - -export type MutationUpdateMessageArgs = { - body: Scalars['String']['input'] - chatId: Scalars['String']['input'] - id: Scalars['Int']['input'] -} - -export type MutationUpdateProfileArgs = { - profile: ProfileInput -} - -export type MutationUpdateReactionArgs = { - id: Scalars['Int']['input'] - reaction: ReactionInput -} - -export type MutationUpdateShoutArgs = { - publish?: InputMaybe - shout_id: Scalars['Int']['input'] - shout_input?: InputMaybe -} - -export type MutationUpdateTopicArgs = { - input: TopicInput -} - -export type MySubscriptionsQueryResult = { - authors: Array> - topics: Array> -} - -export type Notification = { - createdAt: Scalars['DateTime']['output'] - data?: Maybe - id: Scalars['Int']['output'] - occurrences: Scalars['Int']['output'] - reaction?: Maybe - seen: Scalars['Boolean']['output'] - shout?: Maybe - type: NotificationType -} - -export enum NotificationType { - NewComment = 'NEW_COMMENT', - NewReply = 'NEW_REPLY', -} - -export type NotificationsQueryParams = { - limit?: InputMaybe - offset?: InputMaybe -} - -export type NotificationsQueryResult = { - notifications: Array> - totalCount: Scalars['Int']['output'] - totalUnreadCount: Scalars['Int']['output'] -} - -export type Operation = { - id: Scalars['Int']['output'] - name: Scalars['String']['output'] -} - -export type Permission = { - operation: Scalars['Int']['output'] - resource: Scalars['Int']['output'] -} - -export type ProfileInput = { - about?: InputMaybe - bio?: InputMaybe - links?: InputMaybe>> - name?: InputMaybe - slug?: InputMaybe - userpic?: InputMaybe -} - -export type Query = { - authorsAll: Array> - getAuthor?: Maybe - getTopic?: Maybe - isEmailUsed: Scalars['Boolean']['output'] - loadAuthorsBy: Array> - loadChats: Result - loadDrafts: Array> - loadMessagesBy: Result - loadMySubscriptions?: Maybe - loadNotifications: NotificationsQueryResult - loadRandomTopShouts: Array> - loadRandomTopicShouts: RandomTopicShoutsQueryResult - loadReactionsBy: Array> - loadRecipients: Result - loadShout?: Maybe - loadShouts: Array> - loadUnratedShouts: Array> - markdownBody: Scalars['String']['output'] - myFeed?: Maybe>> - searchMessages: Result - searchRecipients: Result - signIn: AuthResult - signOut: AuthResult - topicsAll: Array> - topicsByAuthor: Array> - topicsByCommunity: Array> - topicsRandom: Array> - userFollowedAuthors: Array> - userFollowedTopics: Array> - userFollowers: Array> -} - -export type QueryGetAuthorArgs = { - slug: Scalars['String']['input'] -} - -export type QueryGetTopicArgs = { - slug: Scalars['String']['input'] -} - -export type QueryIsEmailUsedArgs = { - email: Scalars['String']['input'] -} - -export type QueryLoadAuthorsByArgs = { - by?: InputMaybe - limit?: InputMaybe - offset?: InputMaybe -} - -export type QueryLoadChatsArgs = { - limit?: InputMaybe - offset?: InputMaybe -} - -export type QueryLoadMessagesByArgs = { - by: MessagesBy - limit?: InputMaybe - offset?: InputMaybe -} - -export type QueryLoadNotificationsArgs = { - params: NotificationsQueryParams -} - -export type QueryLoadRandomTopShoutsArgs = { - params?: InputMaybe -} - -export type QueryLoadRandomTopicShoutsArgs = { - limit: Scalars['Int']['input'] -} - -export type QueryLoadReactionsByArgs = { - by: ReactionBy - limit?: InputMaybe - offset?: InputMaybe -} - -export type QueryLoadRecipientsArgs = { - limit?: InputMaybe - offset?: InputMaybe -} - -export type QueryLoadShoutArgs = { - shout_id?: InputMaybe - slug?: InputMaybe -} - -export type QueryLoadShoutsArgs = { - options?: InputMaybe -} - -export type QueryLoadUnratedShoutsArgs = { - limit: Scalars['Int']['input'] -} - -export type QueryMarkdownBodyArgs = { - body: Scalars['String']['input'] -} - -export type QueryMyFeedArgs = { - options?: InputMaybe -} - -export type QuerySearchMessagesArgs = { - by: MessagesBy - limit?: InputMaybe - offset?: InputMaybe -} - -export type QuerySearchRecipientsArgs = { - limit?: InputMaybe - offset?: InputMaybe - query: Scalars['String']['input'] -} - -export type QuerySignInArgs = { - email: Scalars['String']['input'] - lang?: InputMaybe - password?: InputMaybe -} - -export type QueryTopicsByAuthorArgs = { - author: Scalars['String']['input'] -} - -export type QueryTopicsByCommunityArgs = { - community: Scalars['String']['input'] -} - -export type QueryTopicsRandomArgs = { - amount?: InputMaybe -} - -export type QueryUserFollowedAuthorsArgs = { - slug: Scalars['String']['input'] -} - -export type QueryUserFollowedTopicsArgs = { - slug: Scalars['String']['input'] -} - -export type QueryUserFollowersArgs = { - slug: Scalars['String']['input'] -} - -export type RandomTopicShoutsQueryResult = { - shouts: Array> - topic: Topic -} - -export type Rating = { - rater: Scalars['String']['output'] - value: Scalars['Int']['output'] -} - -export type Reaction = { - body?: Maybe - createdAt: Scalars['DateTime']['output'] - createdBy: User - deletedAt?: Maybe - deletedBy?: Maybe - id: Scalars['Int']['output'] - kind: ReactionKind - old_id?: Maybe - old_thread?: Maybe - range?: Maybe - replyTo?: Maybe - shout: Shout - stat?: Maybe - updatedAt?: Maybe -} - -export type ReactionBy = { - comment?: InputMaybe - createdBy?: InputMaybe - days?: InputMaybe - search?: InputMaybe - shout?: InputMaybe - shouts?: InputMaybe>> - sort?: InputMaybe - topic?: InputMaybe -} - -export type ReactionInput = { - body?: InputMaybe - kind: ReactionKind - range?: InputMaybe - replyTo?: InputMaybe - shout: Scalars['Int']['input'] -} - -export enum ReactionKind { - Accept = 'ACCEPT', - Agree = 'AGREE', - Ask = 'ASK', - Comment = 'COMMENT', - Disagree = 'DISAGREE', - Dislike = 'DISLIKE', - Disproof = 'DISPROOF', - Footnote = 'FOOTNOTE', - Like = 'LIKE', - Proof = 'PROOF', - Propose = 'PROPOSE', - Quote = 'QUOTE', - Reject = 'REJECT', - Remark = 'REMARK', -} - -export enum ReactionStatus { - Changed = 'CHANGED', - Deleted = 'DELETED', - Explained = 'EXPLAINED', - New = 'NEW', - Updated = 'UPDATED', -} - -export type ReactionUpdating = { - error?: Maybe - reaction?: Maybe - status?: Maybe -} - -export type Resource = { - id: Scalars['Int']['output'] - name: Scalars['String']['output'] -} - -export type Result = { - author?: Maybe - authors?: Maybe>> - chat?: Maybe - chats?: Maybe>> - communities?: Maybe>> - community?: Maybe - error?: Maybe - members?: Maybe>> - message?: Maybe - messages?: Maybe>> - reaction?: Maybe - reactions?: Maybe>> - shout?: Maybe - shouts?: Maybe>> - slugs?: Maybe>> - topic?: Maybe - topics?: Maybe>> -} - -export type Role = { - community: Scalars['String']['output'] - desc?: Maybe - id: Scalars['Int']['output'] - name: Scalars['String']['output'] - permissions: Array -} - -export type Shout = { - authors?: Maybe>> - body: Scalars['String']['output'] - community?: Maybe - cover?: Maybe - createdAt: Scalars['DateTime']['output'] - deletedAt?: Maybe - deletedBy?: Maybe - description?: Maybe - id: Scalars['Int']['output'] - lang?: Maybe - layout?: Maybe - lead?: Maybe - mainTopic?: Maybe - media?: Maybe - publishedAt?: Maybe - slug: Scalars['String']['output'] - stat?: Maybe - subtitle?: Maybe - title?: Maybe - topics?: Maybe>> - updatedAt?: Maybe - updatedBy?: Maybe - versionOf?: Maybe - visibility?: Maybe -} - -export type ShoutInput = { - authors?: InputMaybe>> - body?: InputMaybe - community?: InputMaybe - cover?: InputMaybe - description?: InputMaybe - layout?: InputMaybe - lead?: InputMaybe - mainTopic?: InputMaybe - media?: InputMaybe - slug?: InputMaybe - subtitle?: InputMaybe - title?: InputMaybe - topics?: InputMaybe>> -} - -export type Stat = { - commented?: Maybe - ranking?: Maybe - rating?: Maybe - reacted?: Maybe - viewed?: Maybe -} - -export type Token = { - createdAt: Scalars['DateTime']['output'] - expiresAt?: Maybe - id: Scalars['Int']['output'] - ownerId: Scalars['Int']['output'] - usedAt?: Maybe - value: Scalars['String']['output'] -} - -export type Topic = { - body?: Maybe - id: Scalars['Int']['output'] - oid?: Maybe - pic?: Maybe - slug: Scalars['String']['output'] - stat?: Maybe - title?: Maybe -} - -export type TopicInput = { - body?: InputMaybe - id?: InputMaybe - pic?: InputMaybe - slug: Scalars['String']['input'] - title?: InputMaybe -} - -export type TopicStat = { - authors: Scalars['Int']['output'] - followers: Scalars['Int']['output'] - shouts: Scalars['Int']['output'] -} - -export type User = { - about?: Maybe - bio?: Maybe - communities?: Maybe>> - createdAt: Scalars['DateTime']['output'] - email?: Maybe - emailConfirmed?: Maybe - id: Scalars['Int']['output'] - lastSeen?: Maybe - links?: Maybe>> - muted?: Maybe - name?: Maybe - oauth?: Maybe - oid?: Maybe - password?: Maybe - ratings?: Maybe>> - slug: Scalars['String']['output'] - updatedAt?: Maybe - username: Scalars['String']['output'] - userpic?: Maybe -} diff --git a/src/stores/zine/authors.ts b/src/stores/zine/authors.ts index 099d4e18..db3f0627 100644 --- a/src/stores/zine/authors.ts +++ b/src/stores/zine/authors.ts @@ -1,5 +1,5 @@ import { createLazyMemo } from '@solid-primitives/memo' -import { createMemo, createSignal } from 'solid-js' +import { createSignal } from 'solid-js' import { apiClient } from '../../graphql/client/core' import { Author, QueryLoad_Authors_ByArgs } from '../../graphql/schema/core.gen' diff --git a/src/utils/apiClient.ts b/src/utils/apiClient.ts deleted file mode 100644 index ed0dbcc1..00000000 --- a/src/utils/apiClient.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { searchUrl } from './config' - -type ApiErrorCode = - | 'unknown' - | 'email_not_confirmed' - | 'user_not_found' - | 'user_already_exists' - | 'token_expired' - | 'token_invalid' - | 'duplicate_slug' - -export class ApiError extends Error { - code: ApiErrorCode - - constructor(code: ApiErrorCode, message?: string) { - super(message) - this.code = code - } -} - -export const apiClient = { - getSearchResults: async (searchValue: string) => { - return await fetch(`${searchUrl}/search?q=${searchValue}`, { - method: 'GET', - headers: { - accept: 'application/json', - 'content-type': 'application/json; charset=utf-8', - }, - }) - }, -}