From 6b938415a07dcdf98de1e71f4b7c62de0606eddb Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 19 Aug 2020 14:14:51 -0400 Subject: [PATCH] Switch front end to use lemmy-js-client. Fixes #1090 --- README.md | 1 + ui/package.json | 1 + ui/src/api_tests/comment.spec.ts | 2 +- ui/src/api_tests/shared.ts | 6 +- ui/src/components/admin-settings.tsx | 2 +- ui/src/components/comment-form.tsx | 2 +- ui/src/components/comment-node.tsx | 5 +- ui/src/components/comment-nodes.tsx | 4 +- ui/src/components/communities.tsx | 4 +- ui/src/components/community-form.tsx | 4 +- ui/src/components/community-link.tsx | 2 +- ui/src/components/community.tsx | 28 +- ui/src/components/create-community.tsx | 2 +- ui/src/components/create-post.tsx | 2 +- ui/src/components/create-private-message.tsx | 2 +- ui/src/components/footer.tsx | 2 +- ui/src/components/iframely-card.tsx | 2 +- ui/src/components/inbox.tsx | 6 +- ui/src/components/instances.tsx | 2 +- ui/src/components/listing-type-select.tsx | 10 +- ui/src/components/login.tsx | 2 +- ui/src/components/main.tsx | 40 +- ui/src/components/modlog.tsx | 2 +- ui/src/components/navbar.tsx | 8 +- ui/src/components/password_change.tsx | 2 +- ui/src/components/post-form.tsx | 12 +- ui/src/components/post-listing.tsx | 4 +- ui/src/components/post-listings.tsx | 2 +- ui/src/components/post.tsx | 9 +- ui/src/components/private-message-form.tsx | 4 +- ui/src/components/private-message.tsx | 2 +- ui/src/components/search.tsx | 24 +- ui/src/components/setup.tsx | 2 +- ui/src/components/sidebar.tsx | 2 +- ui/src/components/site-form.tsx | 2 +- ui/src/components/sort-select.tsx | 9 +- ui/src/components/sponsors.tsx | 2 +- ui/src/components/user-details.tsx | 8 +- ui/src/components/user-listing.tsx | 2 +- ui/src/components/user.tsx | 52 +- ui/src/interfaces.ts | 1052 ------------------ ui/src/services/UserService.ts | 7 +- ui/src/services/WebSocketService.ts | 218 ++-- ui/src/utils.ts | 38 +- ui/yarn.lock | 5 + 45 files changed, 292 insertions(+), 1307 deletions(-) diff --git a/README.md b/README.md index 8aa5fe38a..57b3d63e5 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,7 @@ Each Lemmy server can set its own moderation policy; appointing site-wide admins ### Libraries +- [lemmy-js-client](https://github.com/LemmyNet/lemmy-js-client) - [Kotlin API ( under development )](https://github.com/eiknat/lemmy-client) ## Support / Donate diff --git a/ui/package.json b/ui/package.json index 06c52807a..6d8c5183c 100644 --- a/ui/package.json +++ b/ui/package.json @@ -37,6 +37,7 @@ "inferno-router": "^7.4.2", "js-cookie": "^2.2.0", "jwt-decode": "^2.2.0", + "lemmy-js-client": "^1.0.2", "markdown-it": "^11.0.0", "markdown-it-container": "^3.0.0", "markdown-it-emoji": "^1.4.0", diff --git a/ui/src/api_tests/comment.spec.ts b/ui/src/api_tests/comment.spec.ts index 02cc683c4..a7efefeac 100644 --- a/ui/src/api_tests/comment.spec.ts +++ b/ui/src/api_tests/comment.spec.ts @@ -21,7 +21,7 @@ import { API, } from './shared'; -import { PostResponse } from '../interfaces'; +import { PostResponse } from 'lemmy-js-client'; let postRes: PostResponse; diff --git a/ui/src/api_tests/shared.ts b/ui/src/api_tests/shared.ts index 31530ef7e..7aa46e5de 100644 --- a/ui/src/api_tests/shared.ts +++ b/ui/src/api_tests/shared.ts @@ -36,7 +36,7 @@ import { SortType, ListingType, GetSiteResponse, -} from '../interfaces'; +} from 'lemmy-js-client'; export interface API { url: string; @@ -668,8 +668,8 @@ export async function saveUserSettingsBio( let form: UserSettingsForm = { show_nsfw: true, theme: 'darkly', - default_sort_type: SortType.Active, - default_listing_type: ListingType.All, + default_sort_type: Object.keys(SortType).indexOf(SortType.Active), + default_listing_type: Object.keys(ListingType).indexOf(ListingType.All), lang: 'en', show_avatars: true, send_notifications_to_email: false, diff --git a/ui/src/components/admin-settings.tsx b/ui/src/components/admin-settings.tsx index fe50b1e94..a3bfdd813 100644 --- a/ui/src/components/admin-settings.tsx +++ b/ui/src/components/admin-settings.tsx @@ -9,7 +9,7 @@ import { SiteConfigForm, GetSiteConfigResponse, WebSocketJsonResponse, -} from '../interfaces'; +} from 'lemmy-js-client'; import { WebSocketService } from '../services'; import { wsJsonToRes, capitalizeFirstLetter, toast, randomStr } from '../utils'; import autosize from 'autosize'; diff --git a/ui/src/components/comment-form.tsx b/ui/src/components/comment-form.tsx index 5597f58ee..dbd14dc76 100644 --- a/ui/src/components/comment-form.tsx +++ b/ui/src/components/comment-form.tsx @@ -8,7 +8,7 @@ import { WebSocketJsonResponse, UserOperation, CommentResponse, -} from '../interfaces'; +} from 'lemmy-js-client'; import { capitalizeFirstLetter, wsJsonToRes } from '../utils'; import { WebSocketService, UserService } from '../services'; import { i18n } from '../i18next'; diff --git a/ui/src/components/comment-node.tsx b/ui/src/components/comment-node.tsx index 13263b822..1992c4fc8 100644 --- a/ui/src/components/comment-node.tsx +++ b/ui/src/components/comment-node.tsx @@ -16,10 +16,9 @@ import { AddAdminForm, TransferCommunityForm, TransferSiteForm, - BanType, - CommentSortType, SortType, -} from '../interfaces'; +} from 'lemmy-js-client'; +import { CommentSortType, BanType } from '../interfaces'; import { WebSocketService, UserService } from '../services'; import { mdToHtml, diff --git a/ui/src/components/comment-nodes.tsx b/ui/src/components/comment-nodes.tsx index 62693f766..bdb8a545e 100644 --- a/ui/src/components/comment-nodes.tsx +++ b/ui/src/components/comment-nodes.tsx @@ -1,11 +1,11 @@ import { Component } from 'inferno'; +import { CommentSortType } from '../interfaces'; import { CommentNode as CommentNodeI, CommunityUser, UserView, - CommentSortType, SortType, -} from '../interfaces'; +} from 'lemmy-js-client'; import { commentSort, commentSortSortType } from '../utils'; import { CommentNode } from './comment-node'; diff --git a/ui/src/components/communities.tsx b/ui/src/components/communities.tsx index 038e4517f..5be032c5e 100644 --- a/ui/src/components/communities.tsx +++ b/ui/src/components/communities.tsx @@ -13,7 +13,7 @@ import { WebSocketJsonResponse, GetSiteResponse, Site, -} from '../interfaces'; +} from 'lemmy-js-client'; import { WebSocketService } from '../services'; import { wsJsonToRes, toast, getPageFromProps } from '../utils'; import { CommunityLink } from './community-link'; @@ -218,7 +218,7 @@ export class Communities extends Component { refetch() { let listCommunitiesForm: ListCommunitiesForm = { - sort: SortType[SortType.TopAll], + sort: SortType.TopAll, limit: communityLimit, page: this.state.page, }; diff --git a/ui/src/components/community-form.tsx b/ui/src/components/community-form.tsx index 1ae96ac8b..7b8c379ba 100644 --- a/ui/src/components/community-form.tsx +++ b/ui/src/components/community-form.tsx @@ -9,12 +9,12 @@ import { ListCategoriesResponse, CommunityResponse, WebSocketJsonResponse, -} from '../interfaces'; + Community, +} from 'lemmy-js-client'; import { WebSocketService } from '../services'; import { wsJsonToRes, capitalizeFirstLetter, toast, randomStr } from '../utils'; import { i18n } from '../i18next'; -import { Community } from '../interfaces'; import { MarkdownTextArea } from './markdown-textarea'; import { ImageUploadForm } from './image-upload-form'; diff --git a/ui/src/components/community-link.tsx b/ui/src/components/community-link.tsx index 293ded046..003f61e14 100644 --- a/ui/src/components/community-link.tsx +++ b/ui/src/components/community-link.tsx @@ -1,6 +1,6 @@ import { Component } from 'inferno'; import { Link } from 'inferno-router'; -import { Community } from '../interfaces'; +import { Community } from 'lemmy-js-client'; import { hostname, pictrsAvatarThumbnail, showAvatars } from '../utils'; interface CommunityOther { diff --git a/ui/src/components/community.tsx b/ui/src/components/community.tsx index 1fe75c598..f86562f8c 100644 --- a/ui/src/components/community.tsx +++ b/ui/src/components/community.tsx @@ -2,6 +2,7 @@ import { Component, linkEvent } from 'inferno'; import { Helmet } from 'inferno-helmet'; import { Subscription } from 'rxjs'; import { retryWhen, delay, take } from 'rxjs/operators'; +import { DataType } from '../interfaces'; import { UserOperation, Community as CommunityI, @@ -14,7 +15,6 @@ import { GetPostsForm, GetCommunityForm, ListingType, - DataType, GetPostsResponse, PostResponse, AddModToCommunityResponse, @@ -26,7 +26,7 @@ import { WebSocketJsonResponse, GetSiteResponse, Site, -} from '../interfaces'; +} from 'lemmy-js-client'; import { WebSocketService } from '../services'; import { PostListings } from './post-listings'; import { CommentNodes } from './comment-nodes'; @@ -78,7 +78,7 @@ interface CommunityProps { interface UrlParams { dataType?: string; - sort?: string; + sort?: SortType; page?: number; } @@ -287,9 +287,7 @@ export class Community extends Component { { } handleSortChange(val: SortType) { - this.updateUrl({ sort: SortType[val].toLowerCase(), page: 1 }); + this.updateUrl({ sort: val, page: 1 }); window.scrollTo(0, 0); } handleDataTypeChange(val: DataType) { - this.updateUrl({ dataType: DataType[val].toLowerCase(), page: 1 }); + this.updateUrl({ dataType: DataType[val], page: 1 }); window.scrollTo(0, 0); } updateUrl(paramUpdates: UrlParams) { - const dataTypeStr = - paramUpdates.dataType || DataType[this.state.dataType].toLowerCase(); - const sortStr = - paramUpdates.sort || SortType[this.state.sort].toLowerCase(); + const dataTypeStr = paramUpdates.dataType || DataType[this.state.dataType]; + const sortStr = paramUpdates.sort || this.state.sort; const page = paramUpdates.page || this.state.page; this.props.history.push( `/c/${this.state.community.name}/data_type/${dataTypeStr}/sort/${sortStr}/page/${page}` @@ -361,8 +357,8 @@ export class Community extends Component { let getPostsForm: GetPostsForm = { page: this.state.page, limit: fetchLimit, - sort: SortType[this.state.sort], - type_: ListingType[ListingType.Community], + sort: this.state.sort, + type_: ListingType.Community, community_id: this.state.community.id, }; WebSocketService.Instance.getPosts(getPostsForm); @@ -370,8 +366,8 @@ export class Community extends Component { let getCommentsForm: GetCommentsForm = { page: this.state.page, limit: fetchLimit, - sort: SortType[this.state.sort], - type_: ListingType[ListingType.Community], + sort: this.state.sort, + type_: ListingType.Community, community_id: this.state.community.id, }; WebSocketService.Instance.getComments(getCommentsForm); diff --git a/ui/src/components/create-community.tsx b/ui/src/components/create-community.tsx index 8317ffbe8..6f156211d 100644 --- a/ui/src/components/create-community.tsx +++ b/ui/src/components/create-community.tsx @@ -9,7 +9,7 @@ import { WebSocketJsonResponse, GetSiteResponse, Site, -} from '../interfaces'; +} from 'lemmy-js-client'; import { toast, wsJsonToRes } from '../utils'; import { WebSocketService, UserService } from '../services'; import { i18n } from '../i18next'; diff --git a/ui/src/components/create-post.tsx b/ui/src/components/create-post.tsx index eb86d8f88..f4c03b653 100644 --- a/ui/src/components/create-post.tsx +++ b/ui/src/components/create-post.tsx @@ -11,7 +11,7 @@ import { WebSocketJsonResponse, GetSiteResponse, Site, -} from '../interfaces'; +} from 'lemmy-js-client'; import { i18n } from '../i18next'; interface CreatePostState { diff --git a/ui/src/components/create-private-message.tsx b/ui/src/components/create-private-message.tsx index ed06a66ae..98c69d5b7 100644 --- a/ui/src/components/create-private-message.tsx +++ b/ui/src/components/create-private-message.tsx @@ -10,7 +10,7 @@ import { GetSiteResponse, Site, PrivateMessageFormParams, -} from '../interfaces'; +} from 'lemmy-js-client'; import { toast, wsJsonToRes } from '../utils'; import { i18n } from '../i18next'; diff --git a/ui/src/components/footer.tsx b/ui/src/components/footer.tsx index 6e7acb7a0..62585ff30 100644 --- a/ui/src/components/footer.tsx +++ b/ui/src/components/footer.tsx @@ -9,7 +9,7 @@ import { UserOperation, WebSocketJsonResponse, GetSiteResponse, -} from '../interfaces'; +} from 'lemmy-js-client'; interface FooterState { version: string; diff --git a/ui/src/components/iframely-card.tsx b/ui/src/components/iframely-card.tsx index 1a47f377a..6a604f7c5 100644 --- a/ui/src/components/iframely-card.tsx +++ b/ui/src/components/iframely-card.tsx @@ -1,5 +1,5 @@ import { Component, linkEvent } from 'inferno'; -import { Post } from '../interfaces'; +import { Post } from 'lemmy-js-client'; import { mdToHtml } from '../utils'; import { i18n } from '../i18next'; diff --git a/ui/src/components/inbox.tsx b/ui/src/components/inbox.tsx index ecc9223c3..4da86e351 100644 --- a/ui/src/components/inbox.tsx +++ b/ui/src/components/inbox.tsx @@ -19,7 +19,7 @@ import { PrivateMessageResponse, GetSiteResponse, Site, -} from '../interfaces'; +} from 'lemmy-js-client'; import { WebSocketService, UserService } from '../services'; import { wsJsonToRes, @@ -399,7 +399,7 @@ export class Inbox extends Component { refetch() { let repliesForm: GetRepliesForm = { - sort: SortType[this.state.sort], + sort: this.state.sort, unread_only: this.state.unreadOrAll == UnreadOrAll.Unread, page: this.state.page, limit: fetchLimit, @@ -407,7 +407,7 @@ export class Inbox extends Component { WebSocketService.Instance.getReplies(repliesForm); let userMentionsForm: GetUserMentionsForm = { - sort: SortType[this.state.sort], + sort: this.state.sort, unread_only: this.state.unreadOrAll == UnreadOrAll.Unread, page: this.state.page, limit: fetchLimit, diff --git a/ui/src/components/instances.tsx b/ui/src/components/instances.tsx index ae4e3f13b..bcc02480b 100644 --- a/ui/src/components/instances.tsx +++ b/ui/src/components/instances.tsx @@ -6,7 +6,7 @@ import { UserOperation, WebSocketJsonResponse, GetSiteResponse, -} from '../interfaces'; +} from 'lemmy-js-client'; import { WebSocketService } from '../services'; import { wsJsonToRes, toast } from '../utils'; import { i18n } from '../i18next'; diff --git a/ui/src/components/listing-type-select.tsx b/ui/src/components/listing-type-select.tsx index 6bdf457c4..3d12d4343 100644 --- a/ui/src/components/listing-type-select.tsx +++ b/ui/src/components/listing-type-select.tsx @@ -1,7 +1,7 @@ import { Component, linkEvent } from 'inferno'; -import { ListingType } from '../interfaces'; +import { ListingType } from 'lemmy-js-client'; import { UserService } from '../services'; - +import { randomStr } from '../utils'; import { i18n } from '../i18next'; interface ListingTypeSelectProps { @@ -17,6 +17,8 @@ export class ListingTypeSelect extends Component< ListingTypeSelectProps, ListingTypeSelectState > { + private id = `listing-type-input-${randomStr()}`; + private emptyState: ListingTypeSelectState = { type_: this.props.type_, }; @@ -42,6 +44,7 @@ export class ListingTypeSelect extends Component< `} > { } let listCommunitiesForm: ListCommunitiesForm = { - sort: SortType[SortType.Hot], + sort: SortType.Hot, limit: 6, }; @@ -334,13 +334,9 @@ export class Main extends Component { } updateUrl(paramUpdates: UrlParams) { - const listingTypeStr = - paramUpdates.listingType || - ListingType[this.state.listingType].toLowerCase(); - const dataTypeStr = - paramUpdates.dataType || DataType[this.state.dataType].toLowerCase(); - const sortStr = - paramUpdates.sort || SortType[this.state.sort].toLowerCase(); + const listingTypeStr = paramUpdates.listingType || this.state.listingType; + const dataTypeStr = paramUpdates.dataType || DataType[this.state.dataType]; + const sortStr = paramUpdates.sort || this.state.sort; const page = paramUpdates.page || this.state.page; this.props.history.push( `/home/data_type/${dataTypeStr}/listing_type/${listingTypeStr}/sort/${sortStr}/page/${page}` @@ -549,7 +545,7 @@ export class Main extends Component { {this.state.listingType == ListingType.All && ( { {UserService.Instance.user && this.state.listingType == ListingType.Subscribed && ( { } handleSortChange(val: SortType) { - this.updateUrl({ sort: SortType[val].toLowerCase(), page: 1 }); + this.updateUrl({ sort: val, page: 1 }); window.scrollTo(0, 0); } handleListingTypeChange(val: ListingType) { - this.updateUrl({ listingType: ListingType[val].toLowerCase(), page: 1 }); + this.updateUrl({ listingType: val, page: 1 }); window.scrollTo(0, 0); } handleDataTypeChange(val: DataType) { - this.updateUrl({ dataType: DataType[val].toLowerCase(), page: 1 }); + this.updateUrl({ dataType: DataType[val], page: 1 }); window.scrollTo(0, 0); } @@ -650,16 +644,16 @@ export class Main extends Component { let getPostsForm: GetPostsForm = { page: this.state.page, limit: fetchLimit, - sort: SortType[this.state.sort], - type_: ListingType[this.state.listingType], + sort: this.state.sort, + type_: this.state.listingType, }; WebSocketService.Instance.getPosts(getPostsForm); } else { let getCommentsForm: GetCommentsForm = { page: this.state.page, limit: fetchLimit, - sort: SortType[this.state.sort], - type_: ListingType[this.state.listingType], + sort: this.state.sort, + type_: this.state.listingType, }; WebSocketService.Instance.getComments(getCommentsForm); } diff --git a/ui/src/components/modlog.tsx b/ui/src/components/modlog.tsx index 0cc78da73..106015a4a 100644 --- a/ui/src/components/modlog.tsx +++ b/ui/src/components/modlog.tsx @@ -19,7 +19,7 @@ import { WebSocketJsonResponse, GetSiteResponse, Site, -} from '../interfaces'; +} from 'lemmy-js-client'; import { WebSocketService } from '../services'; import { wsJsonToRes, addTypeInfo, fetchLimit, toast } from '../utils'; import { MomentTime } from './moment-time'; diff --git a/ui/src/components/navbar.tsx b/ui/src/components/navbar.tsx index 0ddcbb4cd..4ef5276c3 100644 --- a/ui/src/components/navbar.tsx +++ b/ui/src/components/navbar.tsx @@ -18,7 +18,7 @@ import { PrivateMessage, PrivateMessageResponse, WebSocketJsonResponse, -} from '../interfaces'; +} from 'lemmy-js-client'; import { wsJsonToRes, pictrsAvatarThumbnail, @@ -137,7 +137,7 @@ export class Navbar extends Component { this.context.router.history.push(`/search/`); } else { this.context.router.history.push( - `/search/q/${searchParam}/type/all/sort/topall/page/1` + `/search/q/${searchParam}/type/All/sort/TopAll/page/1` ); } } @@ -477,14 +477,14 @@ export class Navbar extends Component { fetchUnreads() { console.log('Fetching unreads...'); let repliesForm: GetRepliesForm = { - sort: SortType[SortType.New], + sort: SortType.New, unread_only: true, page: 1, limit: fetchLimit, }; let userMentionsForm: GetUserMentionsForm = { - sort: SortType[SortType.New], + sort: SortType.New, unread_only: true, page: 1, limit: fetchLimit, diff --git a/ui/src/components/password_change.tsx b/ui/src/components/password_change.tsx index 5b157f7f6..527f21e04 100644 --- a/ui/src/components/password_change.tsx +++ b/ui/src/components/password_change.tsx @@ -9,7 +9,7 @@ import { WebSocketJsonResponse, GetSiteResponse, Site, -} from '../interfaces'; +} from 'lemmy-js-client'; import { WebSocketService, UserService } from '../services'; import { wsJsonToRes, capitalizeFirstLetter, toast } from '../utils'; import { i18n } from '../i18next'; diff --git a/ui/src/components/post-form.tsx b/ui/src/components/post-form.tsx index 854cff6e9..97b44f5fa 100644 --- a/ui/src/components/post-form.tsx +++ b/ui/src/components/post-form.tsx @@ -18,7 +18,7 @@ import { SearchType, SearchResponse, WebSocketJsonResponse, -} from '../interfaces'; +} from 'lemmy-js-client'; import { WebSocketService, UserService } from '../services'; import { wsJsonToRes, @@ -121,7 +121,7 @@ export class PostForm extends Component { ); let listCommunitiesForm: ListCommunitiesForm = { - sort: SortType[SortType.TopAll], + sort: SortType.TopAll, limit: 9999, }; @@ -405,8 +405,8 @@ export class PostForm extends Component { if (validURL(this.state.postForm.url)) { let form: SearchForm = { q: this.state.postForm.url, - type_: SearchType[SearchType.Url], - sort: SortType[SortType.TopAll], + type_: SearchType.Url, + sort: SortType.TopAll, page: 1, limit: 6, }; @@ -433,8 +433,8 @@ export class PostForm extends Component { fetchSimilarPosts() { let form: SearchForm = { q: this.state.postForm.name, - type_: SearchType[SearchType.Posts], - sort: SortType[SortType.TopAll], + type_: SearchType.Posts, + sort: SortType.TopAll, community_id: this.state.postForm.community_id, page: 1, limit: 6, diff --git a/ui/src/components/post-listing.tsx b/ui/src/components/post-listing.tsx index e3e19e99c..fa4bf3911 100644 --- a/ui/src/components/post-listing.tsx +++ b/ui/src/components/post-listing.tsx @@ -11,14 +11,14 @@ import { SavePostForm, CommunityUser, UserView, - BanType, BanFromCommunityForm, BanUserForm, AddModToCommunityForm, AddAdminForm, TransferSiteForm, TransferCommunityForm, -} from '../interfaces'; +} from 'lemmy-js-client'; +import { BanType } from '../interfaces'; import { MomentTime } from './moment-time'; import { PostForm } from './post-form'; import { IFramelyCard } from './iframely-card'; diff --git a/ui/src/components/post-listings.tsx b/ui/src/components/post-listings.tsx index cd65d9340..2c9b4a882 100644 --- a/ui/src/components/post-listings.tsx +++ b/ui/src/components/post-listings.tsx @@ -1,6 +1,6 @@ import { Component } from 'inferno'; import { Link } from 'inferno-router'; -import { Post, SortType } from '../interfaces'; +import { Post, SortType } from 'lemmy-js-client'; import { postSort } from '../utils'; import { PostListing } from './post-listing'; import { i18n } from '../i18next'; diff --git a/ui/src/components/post.tsx b/ui/src/components/post.tsx index 06f461f3a..e9427a5eb 100644 --- a/ui/src/components/post.tsx +++ b/ui/src/components/post.tsx @@ -11,8 +11,6 @@ import { Comment, MarkCommentAsReadForm, CommentResponse, - CommentSortType, - CommentViewType, CommunityUser, CommunityResponse, CommentNode as CommentNodeI, @@ -28,7 +26,8 @@ import { GetSiteResponse, GetCommunityResponse, WebSocketJsonResponse, -} from '../interfaces'; +} from 'lemmy-js-client'; +import { CommentSortType, CommentViewType } from '../interfaces'; import { WebSocketService, UserService } from '../services'; import { wsJsonToRes, @@ -439,8 +438,8 @@ export class Post extends Component { if (this.state.post.url) { let form: SearchForm = { q: this.state.post.url, - type_: SearchType[SearchType.Url], - sort: SortType[SortType.TopAll], + type_: SearchType.Url, + sort: SortType.TopAll, page: 1, limit: 6, }; diff --git a/ui/src/components/private-message-form.tsx b/ui/src/components/private-message-form.tsx index ff889c240..6d7825cd0 100644 --- a/ui/src/components/private-message-form.tsx +++ b/ui/src/components/private-message-form.tsx @@ -14,7 +14,7 @@ import { GetUserDetailsForm, SortType, WebSocketJsonResponse, -} from '../interfaces'; +} from 'lemmy-js-client'; import { WebSocketService } from '../services'; import { capitalizeFirstLetter, @@ -77,7 +77,7 @@ export class PrivateMessageForm extends Component< this.state.privateMessageForm.recipient_id = this.props.params.recipient_id; let form: GetUserDetailsForm = { user_id: this.state.privateMessageForm.recipient_id, - sort: SortType[SortType.New], + sort: SortType.New, saved_only: false, }; WebSocketService.Instance.getUserDetails(form); diff --git a/ui/src/components/private-message.tsx b/ui/src/components/private-message.tsx index bb6aca4c1..243d12e57 100644 --- a/ui/src/components/private-message.tsx +++ b/ui/src/components/private-message.tsx @@ -4,7 +4,7 @@ import { PrivateMessage as PrivateMessageI, DeletePrivateMessageForm, MarkPrivateMessageAsReadForm, -} from '../interfaces'; +} from 'lemmy-js-client'; import { WebSocketService, UserService } from '../services'; import { mdToHtml, pictrsAvatarThumbnail, showAvatars, toast } from '../utils'; import { MomentTime } from './moment-time'; diff --git a/ui/src/components/search.tsx b/ui/src/components/search.tsx index fc19cab97..a18cc2d8e 100644 --- a/ui/src/components/search.tsx +++ b/ui/src/components/search.tsx @@ -17,7 +17,7 @@ import { WebSocketJsonResponse, GetSiteResponse, Site, -} from '../interfaces'; +} from 'lemmy-js-client'; import { WebSocketService } from '../services'; import { wsJsonToRes, @@ -57,8 +57,8 @@ interface SearchProps { interface UrlParams { q?: string; - type_?: string; - sort?: string; + type_?: SearchType; + sort?: SortType; page?: number; } @@ -461,8 +461,8 @@ export class Search extends Component { search() { let form: SearchForm = { q: this.state.q, - type_: SearchType[this.state.type_], - sort: SortType[this.state.sort], + type_: this.state.type_, + sort: this.state.sort, page: this.state.page, limit: fetchLimit, }; @@ -473,12 +473,12 @@ export class Search extends Component { } handleSortChange(val: SortType) { - this.updateUrl({ sort: SortType[val].toLowerCase(), page: 1 }); + this.updateUrl({ sort: val, page: 1 }); } handleTypeChange(i: Search, event: any) { i.updateUrl({ - type_: SearchType[Number(event.target.value)].toLowerCase(), + type_: SearchType[event.target.value], page: 1, }); } @@ -487,8 +487,8 @@ export class Search extends Component { event.preventDefault(); i.updateUrl({ q: i.state.searchText, - type_: SearchType[i.state.type_].toLowerCase(), - sort: SortType[i.state.sort].toLowerCase(), + type_: i.state.type_, + sort: i.state.sort, page: i.state.page, }); } @@ -499,10 +499,8 @@ export class Search extends Component { updateUrl(paramUpdates: UrlParams) { const qStr = paramUpdates.q || this.state.q; - const typeStr = - paramUpdates.type_ || SearchType[this.state.type_].toLowerCase(); - const sortStr = - paramUpdates.sort || SortType[this.state.sort].toLowerCase(); + const typeStr = paramUpdates.type_ || this.state.type_; + const sortStr = paramUpdates.sort || this.state.sort; const page = paramUpdates.page || this.state.page; this.props.history.push( `/search/q/${qStr}/type/${typeStr}/sort/${sortStr}/page/${page}` diff --git a/ui/src/components/setup.tsx b/ui/src/components/setup.tsx index 7da143791..6360ec5a3 100644 --- a/ui/src/components/setup.tsx +++ b/ui/src/components/setup.tsx @@ -7,7 +7,7 @@ import { LoginResponse, UserOperation, WebSocketJsonResponse, -} from '../interfaces'; +} from 'lemmy-js-client'; import { WebSocketService, UserService } from '../services'; import { wsJsonToRes, toast } from '../utils'; import { SiteForm } from './site-form'; diff --git a/ui/src/components/sidebar.tsx b/ui/src/components/sidebar.tsx index b434bb874..25cbd7972 100644 --- a/ui/src/components/sidebar.tsx +++ b/ui/src/components/sidebar.tsx @@ -8,7 +8,7 @@ import { RemoveCommunityForm, UserView, AddModToCommunityForm, -} from '../interfaces'; +} from 'lemmy-js-client'; import { WebSocketService, UserService } from '../services'; import { mdToHtml, getUnixTime } from '../utils'; import { CommunityForm } from './community-form'; diff --git a/ui/src/components/site-form.tsx b/ui/src/components/site-form.tsx index 98f1259b1..9b572f57e 100644 --- a/ui/src/components/site-form.tsx +++ b/ui/src/components/site-form.tsx @@ -2,7 +2,7 @@ import { Component, linkEvent } from 'inferno'; import { Prompt } from 'inferno-router'; import { MarkdownTextArea } from './markdown-textarea'; import { ImageUploadForm } from './image-upload-form'; -import { Site, SiteForm as SiteFormI } from '../interfaces'; +import { Site, SiteForm as SiteFormI } from 'lemmy-js-client'; import { WebSocketService } from '../services'; import { capitalizeFirstLetter, randomStr } from '../utils'; import { i18n } from '../i18next'; diff --git a/ui/src/components/sort-select.tsx b/ui/src/components/sort-select.tsx index 778ed65ce..1f0fb0557 100644 --- a/ui/src/components/sort-select.tsx +++ b/ui/src/components/sort-select.tsx @@ -1,6 +1,6 @@ import { Component, linkEvent } from 'inferno'; -import { SortType } from '../interfaces'; -import { sortingHelpUrl } from '../utils'; +import { SortType } from 'lemmy-js-client'; +import { sortingHelpUrl, randomStr } from '../utils'; import { i18n } from '../i18next'; interface SortSelectProps { @@ -14,6 +14,7 @@ interface SortSelectState { } export class SortSelect extends Component { + private id = `sort-select-${randomStr()}`; private emptyState: SortSelectState = { sort: this.props.sort, }; @@ -33,6 +34,8 @@ export class SortSelect extends Component { return ( <>