diff options
author | Dessalines <tyhou13@gmx.com> | 2019-08-13 19:52:43 -0700 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2019-08-13 19:52:43 -0700 |
commit | d7ab85ab70478f1ec440c920d726d08b145cef5e (patch) | |
tree | cc799c34a29c4e6070a3f3a34823e7c091cddaad /ui | |
parent | ad4dbbcd7726e75aea1e06111a1af3039cbeca70 (diff) |
Squashed commit of the following:
commit ecd6c5a2f47cbbb2fc4bf482fadd78380303a904
Author: Dessalines <happydooby@gmail.com>
Date: Tue Aug 13 19:49:38 2019 -0700
Adding some docs
commit 3babd09affb1920da3d0a0ceb7e24c8aeeb9cf1a
Author: Dessalines <happydooby@gmail.com>
Date: Tue Aug 13 19:28:46 2019 -0700
Adding save user settings
commit 6e8da9cc9e522d0da668bfa31944c3348cc79620
Merge: 3246d5d c148eef
Author: Dessalines <happydooby@gmail.com>
Date: Tue Aug 13 17:26:25 2019 -0700
Merge branch 'dev' into nsfw
commit b3d4a5c4ce441bcc664704aba44cedb51d887599
Author: Dessalines <happydooby@gmail.com>
Date: Sun Aug 11 20:55:09 2019 -0700
nsfw mostly done, except for settings page.
Diffstat (limited to 'ui')
-rw-r--r-- | ui/package.json | 2 | ||||
-rw-r--r-- | ui/src/components/community-form.tsx | 17 | ||||
-rw-r--r-- | ui/src/components/community.tsx | 4 | ||||
-rw-r--r-- | ui/src/components/login.tsx | 15 | ||||
-rw-r--r-- | ui/src/components/post-form.tsx | 15 | ||||
-rw-r--r-- | ui/src/components/post-listing.tsx | 6 | ||||
-rw-r--r-- | ui/src/components/setup.tsx | 1 | ||||
-rw-r--r-- | ui/src/components/user.tsx | 66 | ||||
-rw-r--r-- | ui/src/interfaces.ts | 15 | ||||
-rw-r--r-- | ui/src/services/WebSocketService.ts | 7 | ||||
-rw-r--r-- | ui/src/translations/en.ts | 3 | ||||
-rw-r--r-- | ui/tslint.json | 2 | ||||
-rw-r--r-- | ui/yarn.lock | 2 |
13 files changed, 144 insertions, 11 deletions
diff --git a/ui/package.json b/ui/package.json index d86725f2..523700a2 100644 --- a/ui/package.json +++ b/ui/package.json @@ -41,6 +41,6 @@ "fuse-box": "^3.1.3", "ts-transform-classcat": "^0.0.2", "ts-transform-inferno": "^4.0.2", - "typescript": "^3.3.3333" + "typescript": "^3.5.3" } } diff --git a/ui/src/components/community-form.tsx b/ui/src/components/community-form.tsx index b039fb4d..833d8a3f 100644 --- a/ui/src/components/community-form.tsx +++ b/ui/src/components/community-form.tsx @@ -30,7 +30,8 @@ export class CommunityForm extends Component<CommunityFormProps, CommunityFormSt communityForm: { name: null, title: null, - category_id: null + category_id: null, + nsfw: false, }, categories: [], loading: false @@ -48,6 +49,7 @@ export class CommunityForm extends Component<CommunityFormProps, CommunityFormSt category_id: this.props.community.category_id, description: this.props.community.description, edit_id: this.props.community.id, + nsfw: this.props.community.nsfw, auth: null } } @@ -105,6 +107,14 @@ export class CommunityForm extends Component<CommunityFormProps, CommunityFormSt </div> <div class="form-group row"> <div class="col-12"> + <div class="form-check"> + <input class="form-check-input" type="checkbox" checked={this.state.communityForm.nsfw} onChange={linkEvent(this, this.handleCommunityNsfwChange)}/> + <label class="form-check-label"><T i18nKey="nsfw">#</T></label> + </div> + </div> + </div> + <div class="form-group row"> + <div class="col-12"> <button type="submit" class="btn btn-secondary mr-2"> {this.state.loading ? <svg class="icon icon-spinner spin"><use xlinkHref="#icon-spinner"></use></svg> : @@ -147,6 +157,11 @@ export class CommunityForm extends Component<CommunityFormProps, CommunityFormSt i.setState(i.state); } + handleCommunityNsfwChange(i: CommunityForm, event: any) { + i.state.communityForm.nsfw = event.target.checked; + i.setState(i.state); + } + handleCancel(i: CommunityForm) { i.props.onCancel(); } diff --git a/ui/src/components/community.tsx b/ui/src/components/community.tsx index 480b909e..b9f9c8b2 100644 --- a/ui/src/components/community.tsx +++ b/ui/src/components/community.tsx @@ -37,6 +37,7 @@ export class Community extends Component<any, State> { number_of_comments: null, published: null, removed: null, + nsfw: false, deleted: null, }, moderators: [], @@ -105,6 +106,9 @@ export class Community extends Component<any, State> { {this.state.community.removed && <small className="ml-2 text-muted font-italic"><T i18nKey="removed">#</T></small> } + {this.state.community.nsfw && + <small className="ml-2 text-muted font-italic"><T i18nKey="nsfw">#</T></small> + } </h5> {this.selects()} <PostListings posts={this.state.posts} /> diff --git a/ui/src/components/login.tsx b/ui/src/components/login.tsx index e7af89ca..66962acc 100644 --- a/ui/src/components/login.tsx +++ b/ui/src/components/login.tsx @@ -28,6 +28,7 @@ export class Login extends Component<any, State> { password: undefined, password_verify: undefined, admin: false, + show_nsfw: false, }, loginLoading: false, registerLoading: false, @@ -127,9 +128,16 @@ export class Login extends Component<any, State> { </div> <div class="form-group row"> <div class="col-sm-10"> + <div class="form-check"> + <input class="form-check-input" type="checkbox" checked={this.state.registerForm.show_nsfw} onChange={linkEvent(this, this.handleRegisterShowNsfwChange)}/> + <label class="form-check-label"><T i18nKey="show_nsfw">#</T></label> + </div> + </div> + </div> + <div class="form-group row"> + <div class="col-sm-10"> <button type="submit" class="btn btn-secondary">{this.state.registerLoading ? <svg class="icon icon-spinner spin"><use xlinkHref="#icon-spinner"></use></svg> : i18n.t('sign_up')}</button> - </div> </div> </form> @@ -181,6 +189,11 @@ export class Login extends Component<any, State> { i.setState(i.state); } + handleRegisterShowNsfwChange(i: Login, event: any) { + i.state.registerForm.show_nsfw = event.target.checked; + i.setState(i.state); + } + parseMessage(msg: any) { let op: UserOperation = msgOp(msg); if (msg.error) { diff --git a/ui/src/components/post-form.tsx b/ui/src/components/post-form.tsx index 79d37b42..704b1cdd 100644 --- a/ui/src/components/post-form.tsx +++ b/ui/src/components/post-form.tsx @@ -31,6 +31,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> { private emptyState: PostFormState = { postForm: { name: null, + nsfw: false, auth: null, community_id: null, creator_id: (UserService.Instance.user) ? UserService.Instance.user.id : null, @@ -54,6 +55,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> { edit_id: this.props.post.id, creator_id: this.props.post.creator_id, url: this.props.post.url, + nsfw: this.props.post.nsfw, auth: null } } @@ -128,6 +130,14 @@ export class PostForm extends Component<PostFormProps, PostFormState> { } <div class="form-group row"> <div class="col-sm-10"> + <div class="form-check"> + <input class="form-check-input" type="checkbox" checked={this.state.postForm.nsfw} onChange={linkEvent(this, this.handlePostNsfwChange)}/> + <label class="form-check-label"><T i18nKey="nsfw">#</T></label> + </div> + </div> + </div> + <div class="form-group row"> + <div class="col-sm-10"> <button type="submit" class="btn btn-secondary mr-2"> {this.state.loading ? <svg class="icon icon-spinner spin"><use xlinkHref="#icon-spinner"></use></svg> : @@ -196,6 +206,11 @@ export class PostForm extends Component<PostFormProps, PostFormState> { i.setState(i.state); } + handlePostNsfwChange(i: PostForm, event: any) { + i.state.postForm.nsfw = event.target.checked; + i.setState(i.state); + } + handleCancel(i: PostForm) { i.props.onCancel(); } diff --git a/ui/src/components/post-listing.tsx b/ui/src/components/post-listing.tsx index ff70783c..ca03b980 100644 --- a/ui/src/components/post-listing.tsx +++ b/ui/src/components/post-listing.tsx @@ -93,6 +93,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> { {post.locked && <small className="ml-2 text-muted font-italic"><T i18nKey="locked">#</T></small> } + {post.nsfw && + <small className="ml-2 text-muted font-italic"><T i18nKey="nsfw">#</T></small> + } { post.url && isImage(post.url) && <> { !this.state.imageExpanded @@ -251,6 +254,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> { edit_id: i.props.post.id, creator_id: i.props.post.creator_id, deleted: !i.props.post.deleted, + nsfw: i.props.post.nsfw, auth: null }; WebSocketService.Instance.editPost(deleteForm); @@ -285,6 +289,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> { creator_id: i.props.post.creator_id, removed: !i.props.post.removed, reason: i.state.removeReason, + nsfw: i.props.post.nsfw, auth: null, }; WebSocketService.Instance.editPost(form); @@ -299,6 +304,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> { community_id: i.props.post.community_id, edit_id: i.props.post.id, creator_id: i.props.post.creator_id, + nsfw: i.props.post.nsfw, locked: !i.props.post.locked, auth: null, }; diff --git a/ui/src/components/setup.tsx b/ui/src/components/setup.tsx index f11dc14e..24a5f2d6 100644 --- a/ui/src/components/setup.tsx +++ b/ui/src/components/setup.tsx @@ -23,6 +23,7 @@ export class Setup extends Component<any, State> { password: undefined, password_verify: undefined, admin: true, + show_nsfw: true, }, doneRegisteringUser: false, userLoading: false, diff --git a/ui/src/components/user.tsx b/ui/src/components/user.tsx index c6a70560..39a13e16 100644 --- a/ui/src/components/user.tsx +++ b/ui/src/components/user.tsx @@ -2,8 +2,8 @@ import { Component, linkEvent } from 'inferno'; import { Link } from 'inferno-router'; import { Subscription } from "rxjs"; import { retryWhen, delay, take } from 'rxjs/operators'; -import { UserOperation, Post, Comment, CommunityUser, GetUserDetailsForm, SortType, UserDetailsResponse, UserView, CommentResponse } from '../interfaces'; -import { WebSocketService } from '../services'; +import { UserOperation, Post, Comment, CommunityUser, GetUserDetailsForm, SortType, UserDetailsResponse, UserView, CommentResponse, UserSettingsForm, LoginResponse } from '../interfaces'; +import { WebSocketService, UserService } from '../services'; import { msgOp, fetchLimit, routeSortTypeToEnum, capitalizeFirstLetter } from '../utils'; import { PostListing } from './post-listing'; import { CommentNodes } from './comment-nodes'; @@ -28,6 +28,8 @@ interface UserState { sort: SortType; page: number; loading: boolean; + userSettingsForm: UserSettingsForm; + userSettingsLoading: boolean; } export class User extends Component<any, UserState> { @@ -54,6 +56,11 @@ export class User extends Component<any, UserState> { view: this.getViewFromProps(this.props), sort: this.getSortTypeFromProps(this.props), page: this.getPageFromProps(this.props), + userSettingsForm: { + show_nsfw: null, + auth: null, + }, + userSettingsLoading: null, } constructor(props: any, context: any) { @@ -75,6 +82,10 @@ export class User extends Component<any, UserState> { this.refetch(); } + get isCurrentUser() { + return UserService.Instance.user && UserService.Instance.user.id == this.state.user.id; + } + getViewFromProps(props: any): View { return (props.match.params.view) ? View[capitalizeFirstLetter(props.match.params.view)] : @@ -131,6 +142,9 @@ export class User extends Component<any, UserState> { </div> <div class="col-12 col-md-3"> {this.userInfo()} + {this.isCurrentUser && + this.userSettings() + } {this.moderates()} {this.follows()} </div> @@ -219,7 +233,7 @@ export class User extends Component<any, UserState> { return ( <div> <h5>{user.name}</h5> - <div>{i18n.t('joined')}<MomentTime data={user} /></div> + <div>{i18n.t('joined')} <MomentTime data={user} /></div> <table class="table table-bordered table-sm mt-2"> <tr> <td><T i18nKey="number_of_points" interpolation={{count: user.post_score}}>#</T></td> @@ -235,6 +249,30 @@ export class User extends Component<any, UserState> { ) } + userSettings() { + return ( + <div> + <h5><T i18nKey="settings">#</T></h5> + <form onSubmit={linkEvent(this, this.handleUserSettingsSubmit)}> + <div class="form-group row"> + <div class="col-12"> + <div class="form-check"> + <input class="form-check-input" type="checkbox" checked={this.state.userSettingsForm.show_nsfw} onChange={linkEvent(this, this.handleUserSettingsShowNsfwChange)}/> + <label class="form-check-label"><T i18nKey="show_nsfw">#</T></label> + </div> + </div> + </div> + <div class="form-group row"> + <div class="col-12"> + <button type="submit" class="btn btn-secondary">{this.state.userSettingsLoading ? + <svg class="icon icon-spinner spin"><use xlinkHref="#icon-spinner"></use></svg> : capitalizeFirstLetter(i18n.t('save'))}</button> + </div> + </div> + </form> + </div> + ) + } + moderates() { return ( <div> @@ -329,6 +367,19 @@ export class User extends Component<any, UserState> { i.refetch(); } + handleUserSettingsShowNsfwChange(i: User, event: any) { + i.state.userSettingsForm.show_nsfw = event.target.checked; + i.setState(i.state); + } + + handleUserSettingsSubmit(i: User, event: any) { + event.preventDefault(); + i.state.userSettingsLoading = true; + i.setState(i.state); + + WebSocketService.Instance.saveUserSettings(i.state.userSettingsForm); + } + parseMessage(msg: any) { console.log(msg); let op: UserOperation = msgOp(msg); @@ -343,6 +394,9 @@ export class User extends Component<any, UserState> { this.state.moderates = res.moderates; this.state.posts = res.posts; this.state.loading = false; + if (this.isCurrentUser) { + this.state.userSettingsForm.show_nsfw = UserService.Instance.user.show_nsfw; + } document.title = `/u/${this.state.user.name} - ${WebSocketService.Instance.site.name}`; window.scrollTo(0,0); this.setState(this.state); @@ -378,6 +432,12 @@ export class User extends Component<any, UserState> { if (res.comment.my_vote !== null) found.my_vote = res.comment.my_vote; this.setState(this.state); + } else if (op == UserOperation.SaveUserSettings) { + this.state = this.emptyState; + this.state.userSettingsLoading = false; + this.setState(this.state); + let res: LoginResponse = msg; + UserService.Instance.login(res); } } } diff --git a/ui/src/interfaces.ts b/ui/src/interfaces.ts index 59f4ba1c..ebd42340 100644 --- a/ui/src/interfaces.ts +++ b/ui/src/interfaces.ts @@ -1,5 +1,5 @@ export enum UserOperation { - Login, Register, CreateCommunity, CreatePost, ListCommunities, ListCategories, GetPost, GetCommunity, CreateComment, EditComment, SaveComment, CreateCommentLike, GetPosts, CreatePostLike, EditPost, SavePost, EditCommunity, FollowCommunity, GetFollowedCommunities, GetUserDetails, GetReplies, GetModlog, BanFromCommunity, AddModToCommunity, CreateSite, EditSite, GetSite, AddAdmin, BanUser, Search, MarkAllAsRead + Login, Register, CreateCommunity, CreatePost, ListCommunities, ListCategories, GetPost, GetCommunity, CreateComment, EditComment, SaveComment, CreateCommentLike, GetPosts, CreatePostLike, EditPost, SavePost, EditCommunity, FollowCommunity, GetFollowedCommunities, GetUserDetails, GetReplies, GetModlog, BanFromCommunity, AddModToCommunity, CreateSite, EditSite, GetSite, AddAdmin, BanUser, Search, MarkAllAsRead, SaveUserSettings } export enum CommentSortType { @@ -22,6 +22,7 @@ export interface User { id: number; iss: string; username: string; + show_nsfw: boolean; } export interface UserView { @@ -53,6 +54,7 @@ export interface Community { creator_id: number; removed: boolean; deleted: boolean; + nsfw: boolean; published: string; updated?: string; creator_name: string; @@ -74,11 +76,14 @@ export interface Post { removed: boolean; deleted: boolean; locked: boolean; + nsfw: boolean; published: string; updated?: string; creator_name: string; community_name: string; community_removed: boolean; + community_deleted: boolean; + community_nsfw: boolean; number_of_comments: number; score: number; upvotes: number; @@ -334,6 +339,7 @@ export interface RegisterForm { password: string; password_verify: string; admin: boolean; + show_nsfw: boolean; } export interface LoginResponse { @@ -341,7 +347,10 @@ export interface LoginResponse { jwt: string; } - +export interface UserSettingsForm { + show_nsfw: boolean; + auth: string; +} export interface CommunityForm { name: string; @@ -351,6 +360,7 @@ export interface CommunityForm { edit_id?: number; removed?: boolean; deleted?: boolean; + nsfw: boolean; reason?: string; expires?: number; auth?: string; @@ -396,6 +406,7 @@ export interface PostForm { creator_id: number; removed?: boolean; deleted?: boolean; + nsfw: boolean; locked?: boolean; reason?: string; auth: string; diff --git a/ui/src/services/WebSocketService.ts b/ui/src/services/WebSocketService.ts index c192c2b7..c34b6b3c 100644 --- a/ui/src/services/WebSocketService.ts +++ b/ui/src/services/WebSocketService.ts @@ -1,5 +1,5 @@ import { wsUri } from '../env'; -import { LoginForm, RegisterForm, UserOperation, CommunityForm, PostForm, SavePostForm, CommentForm, SaveCommentForm, CommentLikeForm, GetPostsForm, CreatePostLikeForm, FollowCommunityForm, GetUserDetailsForm, ListCommunitiesForm, GetModlogForm, BanFromCommunityForm, AddModToCommunityForm, AddAdminForm, BanUserForm, SiteForm, Site, UserView, GetRepliesForm, SearchForm } from '../interfaces'; +import { LoginForm, RegisterForm, UserOperation, CommunityForm, PostForm, SavePostForm, CommentForm, SaveCommentForm, CommentLikeForm, GetPostsForm, CreatePostLikeForm, FollowCommunityForm, GetUserDetailsForm, ListCommunitiesForm, GetModlogForm, BanFromCommunityForm, AddModToCommunityForm, AddAdminForm, BanUserForm, SiteForm, Site, UserView, GetRepliesForm, SearchForm, UserSettingsForm } from '../interfaces'; import { webSocket } from 'rxjs/webSocket'; import { Subject } from 'rxjs'; import { retryWhen, delay, take } from 'rxjs/operators'; @@ -184,6 +184,11 @@ export class WebSocketService { this.subject.next(this.wsSendWrapper(UserOperation.MarkAllAsRead, form)); } + public saveUserSettings(userSettingsForm: UserSettingsForm) { + this.setAuth(userSettingsForm); + this.subject.next(this.wsSendWrapper(UserOperation.SaveUserSettings, userSettingsForm)); + } + private wsSendWrapper(op: UserOperation, data: any) { let send = { op: UserOperation[op], data: data }; console.log(send); diff --git a/ui/src/translations/en.ts b/ui/src/translations/en.ts index 7c2b184f..1f79bef2 100644 --- a/ui/src/translations/en.ts +++ b/ui/src/translations/en.ts @@ -29,6 +29,7 @@ export const en = { mod: 'mod', mods: 'mods', moderates: 'Moderates', + settings: 'Settings', remove_as_mod: 'remove as mod', appoint_as_mod: 'appoint as mod', modlog: 'Modlog', @@ -112,6 +113,8 @@ export const en = { setup_admin: 'Set Up Site Administrator', your_site: 'your site', modified: 'modified', + nsfw: 'NSFW', + show_nsfw: 'Show NSFW content', sponsors: 'Sponsors', sponsors_of_lemmy: 'Sponsors of Lemmy', sponsor_message: 'Lemmy is free, <1>open-source</1> software, meaning no advertising, monetizing, or venture capital, ever. Your donations directly support full-time development of the project. Thank you to the following people:', diff --git a/ui/tslint.json b/ui/tslint.json index d3e7a8a9..938502e4 100644 --- a/ui/tslint.json +++ b/ui/tslint.json @@ -2,7 +2,7 @@ "extends": "tslint:recommended", "rules": { "forin": false, - "indent": [ true, "tabs" ], + "indent": [ true, "spaces" ], "interface-name": false, "ban-types": true, "max-classes-per-file": true, diff --git a/ui/yarn.lock b/ui/yarn.lock index f47c16c4..f31f45ae 100644 --- a/ui/yarn.lock +++ b/ui/yarn.lock @@ -2773,7 +2773,7 @@ typescript@^2.6.2: resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c" integrity sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w== -typescript@^3.3.3333: +typescript@^3.5.3: version "3.5.3" resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.3.tgz#c830f657f93f1ea846819e929092f5fe5983e977" integrity sha512-ACzBtm/PhXBDId6a6sDJfroT2pOWt/oOnk4/dElG5G33ZL776N3Y6/6bKZJBFpd+b05F3Ct9qDjMeJmRWtE2/g== |