mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 07:52:13 +00:00
Strongly typing WebsocketJsonResponse. Forgot comment-form.tsx
This commit is contained in:
parent
a044718066
commit
dcd60228ed
18
ui/src/components/comment-form.tsx
vendored
18
ui/src/components/comment-form.tsx
vendored
|
@ -10,9 +10,9 @@ import {
|
|||
} from '../interfaces';
|
||||
import { Subscription } from 'rxjs';
|
||||
import {
|
||||
wsJsonToRes,
|
||||
capitalizeFirstLetter,
|
||||
mentionDropdownFetchLimit,
|
||||
msgOp,
|
||||
mdToHtml,
|
||||
randomStr,
|
||||
markdownHelpUrl,
|
||||
|
@ -311,10 +311,10 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
|
|||
|
||||
this.userSub = WebSocketService.Instance.subject.subscribe(
|
||||
msg => {
|
||||
let op: UserOperation = msgOp(msg);
|
||||
if (op == UserOperation.Search) {
|
||||
let res: SearchResponse = msg;
|
||||
let users = res.users.map(u => {
|
||||
let res = wsJsonToRes(msg);
|
||||
if (res.op == UserOperation.Search) {
|
||||
let data = res.data as SearchResponse;
|
||||
let users = data.users.map(u => {
|
||||
return { key: u.name };
|
||||
});
|
||||
cb(users);
|
||||
|
@ -343,10 +343,10 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
|
|||
|
||||
this.communitySub = WebSocketService.Instance.subject.subscribe(
|
||||
msg => {
|
||||
let op: UserOperation = msgOp(msg);
|
||||
if (op == UserOperation.Search) {
|
||||
let res: SearchResponse = msg;
|
||||
let communities = res.communities.map(u => {
|
||||
let res = wsJsonToRes(msg);
|
||||
if (res.op == UserOperation.Search) {
|
||||
let data = res.data as SearchResponse;
|
||||
let communities = data.communities.map(u => {
|
||||
return { key: u.name };
|
||||
});
|
||||
cb(communities);
|
||||
|
|
3
ui/src/components/communities.tsx
vendored
3
ui/src/components/communities.tsx
vendored
|
@ -10,6 +10,7 @@ import {
|
|||
FollowCommunityForm,
|
||||
ListCommunitiesForm,
|
||||
SortType,
|
||||
WebSocketJsonResponse,
|
||||
} from '../interfaces';
|
||||
import { WebSocketService } from '../services';
|
||||
import { wsJsonToRes } from '../utils';
|
||||
|
@ -227,7 +228,7 @@ export class Communities extends Component<any, CommunitiesState> {
|
|||
WebSocketService.Instance.listCommunities(listCommunitiesForm);
|
||||
}
|
||||
|
||||
parseMessage(msg: any) {
|
||||
parseMessage(msg: WebSocketJsonResponse) {
|
||||
console.log(msg);
|
||||
let res = wsJsonToRes(msg);
|
||||
if (res.error) {
|
||||
|
|
2
ui/src/components/community-form.tsx
vendored
2
ui/src/components/community-form.tsx
vendored
|
@ -239,7 +239,7 @@ export class CommunityForm extends Component<
|
|||
i.props.onCancel();
|
||||
}
|
||||
|
||||
parseMessage(msg: any) {
|
||||
parseMessage(msg: WebSocketJsonResponse) {
|
||||
let res = wsJsonToRes(msg);
|
||||
console.log(msg);
|
||||
if (res.error) {
|
||||
|
|
3
ui/src/components/community.tsx
vendored
3
ui/src/components/community.tsx
vendored
|
@ -14,6 +14,7 @@ import {
|
|||
ListingType,
|
||||
GetPostsResponse,
|
||||
CreatePostLikeResponse,
|
||||
WebSocketJsonResponse,
|
||||
} from '../interfaces';
|
||||
import { WebSocketService, UserService } from '../services';
|
||||
import { PostListings } from './post-listings';
|
||||
|
@ -251,7 +252,7 @@ export class Community extends Component<any, State> {
|
|||
WebSocketService.Instance.getPosts(getPostsForm);
|
||||
}
|
||||
|
||||
parseMessage(msg: any) {
|
||||
parseMessage(msg: WebSocketJsonResponse) {
|
||||
console.log(msg);
|
||||
let res = wsJsonToRes(msg);
|
||||
if (res.error) {
|
||||
|
|
3
ui/src/components/inbox.tsx
vendored
3
ui/src/components/inbox.tsx
vendored
|
@ -12,6 +12,7 @@ import {
|
|||
GetUserMentionsResponse,
|
||||
UserMentionResponse,
|
||||
CommentResponse,
|
||||
WebSocketJsonResponse,
|
||||
} from '../interfaces';
|
||||
import { WebSocketService, UserService } from '../services';
|
||||
import { wsJsonToRes, fetchLimit } from '../utils';
|
||||
|
@ -296,7 +297,7 @@ export class Inbox extends Component<any, InboxState> {
|
|||
WebSocketService.Instance.markAllAsRead();
|
||||
}
|
||||
|
||||
parseMessage(msg: any) {
|
||||
parseMessage(msg: WebSocketJsonResponse) {
|
||||
console.log(msg);
|
||||
let res = wsJsonToRes(msg);
|
||||
if (res.error) {
|
||||
|
|
3
ui/src/components/login.tsx
vendored
3
ui/src/components/login.tsx
vendored
|
@ -8,6 +8,7 @@ import {
|
|||
UserOperation,
|
||||
PasswordResetForm,
|
||||
GetSiteResponse,
|
||||
WebSocketJsonResponse,
|
||||
} from '../interfaces';
|
||||
import { WebSocketService, UserService } from '../services';
|
||||
import { wsJsonToRes, validEmail } from '../utils';
|
||||
|
@ -292,7 +293,7 @@ export class Login extends Component<any, State> {
|
|||
WebSocketService.Instance.passwordReset(resetForm);
|
||||
}
|
||||
|
||||
parseMessage(msg: any) {
|
||||
parseMessage(msg: WebSocketJsonResponse) {
|
||||
let res = wsJsonToRes(msg);
|
||||
if (res.error) {
|
||||
alert(i18n.t(res.error));
|
||||
|
|
3
ui/src/components/main.tsx
vendored
3
ui/src/components/main.tsx
vendored
|
@ -17,6 +17,7 @@ import {
|
|||
CreatePostLikeResponse,
|
||||
Post,
|
||||
GetPostsForm,
|
||||
WebSocketJsonResponse,
|
||||
} from '../interfaces';
|
||||
import { WebSocketService, UserService } from '../services';
|
||||
import { PostListings } from './post-listings';
|
||||
|
@ -561,7 +562,7 @@ export class Main extends Component<any, MainState> {
|
|||
WebSocketService.Instance.getPosts(getPostsForm);
|
||||
}
|
||||
|
||||
parseMessage(msg: any) {
|
||||
parseMessage(msg: WebSocketJsonResponse) {
|
||||
console.log(msg);
|
||||
let res = wsJsonToRes(msg);
|
||||
if (res.error) {
|
||||
|
|
2
ui/src/components/modlog.tsx
vendored
2
ui/src/components/modlog.tsx
vendored
|
@ -422,7 +422,7 @@ export class Modlog extends Component<any, ModlogState> {
|
|||
WebSocketService.Instance.getModlog(modlogForm);
|
||||
}
|
||||
|
||||
parseMessage(msg: any) {
|
||||
parseMessage(msg: WebSocketJsonResponse) {
|
||||
console.log(msg);
|
||||
let res = wsJsonToRes(msg);
|
||||
if (res.error) {
|
||||
|
|
2
ui/src/components/moment-time.tsx
vendored
2
ui/src/components/moment-time.tsx
vendored
|
@ -1,5 +1,5 @@
|
|||
import { Component } from 'inferno';
|
||||
import * as moment from 'moment';
|
||||
import moment from 'moment';
|
||||
import { getMomentLanguage } from '../utils';
|
||||
import { i18n } from '../i18next';
|
||||
|
||||
|
|
3
ui/src/components/navbar.tsx
vendored
3
ui/src/components/navbar.tsx
vendored
|
@ -12,6 +12,7 @@ import {
|
|||
SortType,
|
||||
GetSiteResponse,
|
||||
Comment,
|
||||
WebSocketJsonResponse,
|
||||
} from '../interfaces';
|
||||
import {
|
||||
wsJsonToRes,
|
||||
|
@ -181,7 +182,7 @@ export class Navbar extends Component<any, NavbarState> {
|
|||
i.setState(i.state);
|
||||
}
|
||||
|
||||
parseMessage(msg: any) {
|
||||
parseMessage(msg: WebSocketJsonResponse) {
|
||||
let res = wsJsonToRes(msg);
|
||||
if (res.error) {
|
||||
if (res.error == 'not_logged_in') {
|
||||
|
|
3
ui/src/components/password_change.tsx
vendored
3
ui/src/components/password_change.tsx
vendored
|
@ -5,6 +5,7 @@ import {
|
|||
UserOperation,
|
||||
LoginResponse,
|
||||
PasswordChangeForm,
|
||||
WebSocketJsonResponse,
|
||||
} from '../interfaces';
|
||||
import { WebSocketService, UserService } from '../services';
|
||||
import { wsJsonToRes, capitalizeFirstLetter } from '../utils';
|
||||
|
@ -133,7 +134,7 @@ export class PasswordChange extends Component<any, State> {
|
|||
WebSocketService.Instance.passwordChange(i.state.passwordChangeForm);
|
||||
}
|
||||
|
||||
parseMessage(msg: any) {
|
||||
parseMessage(msg: WebSocketJsonResponse) {
|
||||
let res = wsJsonToRes(msg);
|
||||
if (msg.error) {
|
||||
alert(i18n.t(msg.error));
|
||||
|
|
3
ui/src/components/post-form.tsx
vendored
3
ui/src/components/post-form.tsx
vendored
|
@ -16,6 +16,7 @@ import {
|
|||
SearchType,
|
||||
SearchResponse,
|
||||
GetSiteResponse,
|
||||
WebSocketJsonResponse,
|
||||
} from '../interfaces';
|
||||
import { WebSocketService, UserService } from '../services';
|
||||
import {
|
||||
|
@ -457,7 +458,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
|||
});
|
||||
}
|
||||
|
||||
parseMessage(msg: any) {
|
||||
parseMessage(msg: WebSocketJsonResponse) {
|
||||
let res = wsJsonToRes(msg);
|
||||
if (res.error) {
|
||||
alert(i18n.t(res.error));
|
||||
|
|
3
ui/src/components/post.tsx
vendored
3
ui/src/components/post.tsx
vendored
|
@ -26,6 +26,7 @@ import {
|
|||
SearchResponse,
|
||||
GetSiteResponse,
|
||||
GetCommunityResponse,
|
||||
WebSocketJsonResponse,
|
||||
} from '../interfaces';
|
||||
import { WebSocketService, UserService } from '../services';
|
||||
import { wsJsonToRes, hotRank } from '../utils';
|
||||
|
@ -341,7 +342,7 @@ export class Post extends Component<any, PostState> {
|
|||
);
|
||||
}
|
||||
|
||||
parseMessage(msg: any) {
|
||||
parseMessage(msg: WebSocketJsonResponse) {
|
||||
console.log(msg);
|
||||
let res = wsJsonToRes(msg);
|
||||
if (res.error) {
|
||||
|
|
3
ui/src/components/search.tsx
vendored
3
ui/src/components/search.tsx
vendored
|
@ -12,6 +12,7 @@ import {
|
|||
SearchForm,
|
||||
SearchResponse,
|
||||
SearchType,
|
||||
WebSocketJsonResponse,
|
||||
} from '../interfaces';
|
||||
import { WebSocketService } from '../services';
|
||||
import {
|
||||
|
@ -460,7 +461,7 @@ export class Search extends Component<any, SearchState> {
|
|||
);
|
||||
}
|
||||
|
||||
parseMessage(msg: any) {
|
||||
parseMessage(msg: WebSocketJsonResponse) {
|
||||
console.log(msg);
|
||||
let res = wsJsonToRes(msg);
|
||||
if (res.error) {
|
||||
|
|
9
ui/src/components/setup.tsx
vendored
9
ui/src/components/setup.tsx
vendored
|
@ -1,7 +1,12 @@
|
|||
import { Component, linkEvent } from 'inferno';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { retryWhen, delay, take } from 'rxjs/operators';
|
||||
import { RegisterForm, LoginResponse, UserOperation } from '../interfaces';
|
||||
import {
|
||||
RegisterForm,
|
||||
LoginResponse,
|
||||
UserOperation,
|
||||
WebSocketJsonResponse,
|
||||
} from '../interfaces';
|
||||
import { WebSocketService, UserService } from '../services';
|
||||
import { wsJsonToRes } from '../utils';
|
||||
import { SiteForm } from './site-form';
|
||||
|
@ -181,7 +186,7 @@ export class Setup extends Component<any, State> {
|
|||
i.setState(i.state);
|
||||
}
|
||||
|
||||
parseMessage(msg: any) {
|
||||
parseMessage(msg: WebSocketJsonResponse) {
|
||||
let res = wsJsonToRes(msg);
|
||||
if (res.error) {
|
||||
alert(i18n.t(res.error));
|
||||
|
|
3
ui/src/components/user.tsx
vendored
3
ui/src/components/user.tsx
vendored
|
@ -18,6 +18,7 @@ import {
|
|||
BanUserResponse,
|
||||
AddAdminResponse,
|
||||
DeleteAccountForm,
|
||||
WebSocketJsonResponse,
|
||||
} from '../interfaces';
|
||||
import { WebSocketService, UserService } from '../services';
|
||||
import {
|
||||
|
@ -968,7 +969,7 @@ export class User extends Component<any, UserState> {
|
|||
WebSocketService.Instance.deleteAccount(i.state.deleteAccountForm);
|
||||
}
|
||||
|
||||
parseMessage(msg: any) {
|
||||
parseMessage(msg: WebSocketJsonResponse) {
|
||||
console.log(msg);
|
||||
let res = wsJsonToRes(msg);
|
||||
if (res.error) {
|
||||
|
|
6
ui/src/interfaces.ts
vendored
6
ui/src/interfaces.ts
vendored
|
@ -726,3 +726,9 @@ export interface WebSocketResponse {
|
|||
data: ResponseType;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export interface WebSocketJsonResponse {
|
||||
op: string;
|
||||
data: ResponseType;
|
||||
error?: string;
|
||||
}
|
||||
|
|
3
ui/src/utils.ts
vendored
3
ui/src/utils.ts
vendored
|
@ -16,6 +16,7 @@ import {
|
|||
ListingType,
|
||||
SearchType,
|
||||
WebSocketResponse,
|
||||
WebSocketJsonResponse,
|
||||
} from './interfaces';
|
||||
import { UserService } from './services/UserService';
|
||||
import markdown_it from 'markdown-it';
|
||||
|
@ -39,7 +40,7 @@ export function randomStr() {
|
|||
.substr(2, 10);
|
||||
}
|
||||
|
||||
export function wsJsonToRes(msg: any): WebSocketResponse {
|
||||
export function wsJsonToRes(msg: WebSocketJsonResponse): WebSocketResponse {
|
||||
let opStr: string = msg.op;
|
||||
return {
|
||||
op: UserOperation[opStr],
|
||||
|
|
Loading…
Reference in a new issue