Browse Source

Adding stickied posts.

- Fixes #245
pull/1/head
Dessalines 3 years ago
parent
commit
9babc93437
  1. 13
      src/components/modlog.tsx
  2. 19
      src/components/post-listing.tsx
  3. 15
      src/interfaces.ts
  4. 3
      src/translations/en.ts

13
src/components/modlog.tsx

@ -2,14 +2,15 @@ import { Component, linkEvent } from 'inferno';
import { Link } from 'inferno-router';
import { Subscription } from "rxjs";
import { retryWhen, delay, take } from 'rxjs/operators';
import { UserOperation, GetModlogForm, GetModlogResponse, ModRemovePost, ModLockPost, ModRemoveComment, ModRemoveCommunity, ModBanFromCommunity, ModBan, ModAddCommunity, ModAdd } from '../interfaces';
import { UserOperation, GetModlogForm, GetModlogResponse, ModRemovePost, ModLockPost, ModStickyPost, ModRemoveComment, ModRemoveCommunity, ModBanFromCommunity, ModBan, ModAddCommunity, ModAdd } from '../interfaces';
import { WebSocketService } from '../services';
import { msgOp, addTypeInfo, fetchLimit } from '../utils';
import { MomentTime } from './moment-time';
import * as moment from 'moment';
import { i18n } from '../i18next';
interface ModlogState {
combined: Array<{type_: string, data: ModRemovePost | ModLockPost | ModRemoveCommunity | ModAdd | ModBan}>,
combined: Array<{type_: string, data: ModRemovePost | ModLockPost | ModStickyPost | ModRemoveCommunity | ModAdd | ModBan}>,
communityId?: number,
communityName?: string,
page: number;
@ -51,6 +52,7 @@ export class Modlog extends Component<any, ModlogState> {
setCombined(res: GetModlogResponse) {
let removed_posts = addTypeInfo(res.removed_posts, "removed_posts");
let locked_posts = addTypeInfo(res.locked_posts, "locked_posts");
let stickied_posts = addTypeInfo(res.stickied_posts, "stickied_posts");
let removed_comments = addTypeInfo(res.removed_comments, "removed_comments");
let removed_communities = addTypeInfo(res.removed_communities, "removed_communities");
let banned_from_community = addTypeInfo(res.banned_from_community, "banned_from_community");
@ -61,6 +63,7 @@ export class Modlog extends Component<any, ModlogState> {
this.state.combined.push(...removed_posts);
this.state.combined.push(...locked_posts);
this.state.combined.push(...stickied_posts);
this.state.combined.push(...removed_comments);
this.state.combined.push(...removed_communities);
this.state.combined.push(...banned_from_community);
@ -99,6 +102,12 @@ export class Modlog extends Component<any, ModlogState> {
<span> Post <Link to={`/post/${(i.data as ModLockPost).post_id}`}>{(i.data as ModLockPost).post_name}</Link></span>
</>
}
{i.type_ == 'stickied_posts' &&
<>
{(i.data as ModStickyPost).stickied? 'Stickied' : 'Unstickied'}
<span> Post <Link to={`/post/${(i.data as ModStickyPost).post_id}`}>{(i.data as ModStickyPost).post_name}</Link></span>
</>
}
{i.type_ == 'removed_comments' &&
<>
{(i.data as ModRemoveComment).removed? 'Removed' : 'Restored'}

19
src/components/post-listing.tsx

@ -129,6 +129,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
{post.locked &&
<small className="ml-2 text-muted font-italic"><T i18nKey="locked">#</T></small>
}
{post.stickied &&
<small className="ml-2 text-muted font-italic"><T i18nKey="stickied">#</T></small>
}
{post.nsfw &&
<small className="ml-2 text-muted font-italic"><T i18nKey="nsfw">#</T></small>
}
@ -202,6 +205,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
<li className="list-inline-item">
<span class="pointer" onClick={linkEvent(this, this.handleModLock)}>{post.locked ? i18n.t('unlock') : i18n.t('lock')}</span>
</li>
<li className="list-inline-item">
<span class="pointer" onClick={linkEvent(this, this.handleModSticky)}>{post.stickied ? i18n.t('unsticky') : i18n.t('sticky')}</span>
</li>
</>
}
{/* Mods can ban from community, and appoint as mods to community */}
@ -459,6 +465,19 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
WebSocketService.Instance.editPost(form);
}
handleModSticky(i: PostListing) {
let form: PostFormI = {
name: i.props.post.name,
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,
stickied: !i.props.post.stickied,
auth: null,
};
WebSocketService.Instance.editPost(form);
}
handleModBanFromCommunityShow(i: PostListing) {
i.state.showBanDialog = true;
i.state.banType = BanType.Community;

15
src/interfaces.ts

@ -77,6 +77,7 @@ export interface Post {
removed: boolean;
deleted: boolean;
locked: boolean;
stickied: boolean;
nsfw: boolean;
banned: boolean;
banned_from_community: boolean;
@ -235,6 +236,7 @@ export interface GetModlogResponse {
op: string;
removed_posts: Array<ModRemovePost>,
locked_posts: Array<ModLockPost>,
stickied_posts: Array<ModStickyPost>,
removed_comments: Array<ModRemoveComment>,
removed_communities: Array<ModRemoveCommunity>,
banned_from_community: Array<ModBanFromCommunity>,
@ -268,6 +270,18 @@ export interface ModLockPost {
community_name: string,
}
export interface ModStickyPost {
id: number,
mod_user_id: number,
post_id: number,
stickied?: boolean,
when_: string,
mod_user_name: string,
post_name: string,
community_id: number,
community_name: string,
}
export interface ModRemoveComment {
id: number,
mod_user_id: number,
@ -425,6 +439,7 @@ export interface PostForm {
deleted?: boolean;
nsfw: boolean;
locked?: boolean;
stickied?: boolean;
reason?: string;
auth: string;
}

3
src/translations/en.ts

@ -32,6 +32,8 @@ export const en = {
view_source: 'view source',
unlock: 'unlock',
lock: 'lock',
sticky: 'sticky',
unsticky: 'unsticky',
link: 'link',
mod: 'mod',
mods: 'mods',
@ -47,6 +49,7 @@ export const en = {
remove: 'remove',
removed: 'removed',
locked: 'locked',
stickied: 'stickied',
reason: 'Reason',
mark_as_read: 'mark as read',
mark_as_unread: 'mark as unread',

Loading…
Cancel
Save