Remove categories

This commit is contained in:
Felix Ableitner 2021-03-03 17:59:57 +01:00
parent cc215fe99f
commit e02075d52d
9 changed files with 6 additions and 91 deletions

View file

@ -67,7 +67,7 @@
"eslint": "^7.20.0",
"eslint-plugin-prettier": "^3.3.1",
"husky": "^5.1.0",
"lemmy-js-client": "0.9.9",
"lemmy-js-client": "0.10.0-rc.1",
"lint-staged": "^10.5.4",
"mini-css-extract-plugin": "^1.3.8",
"node-fetch": "^2.6.1",

View file

@ -124,7 +124,6 @@ export class Communities extends Component<any, CommunitiesState> {
<thead class="pointer">
<tr>
<th>{i18n.t("name")}</th>
<th>{i18n.t("category")}</th>
<th class="text-right">{i18n.t("subscribers")}</th>
<th class="text-right">
{i18n.t("users")} / {i18n.t("month")}
@ -144,7 +143,6 @@ export class Communities extends Component<any, CommunitiesState> {
<td>
<CommunityLink community={cv.community} />
</td>
<td>{cv.category.name}</td>
<td class="text-right">{cv.counts.subscribers}</td>
<td class="text-right">{cv.counts.users_active_month}</td>
<td class="text-right d-none d-lg-table-cell">

View file

@ -5,7 +5,6 @@ import {
EditCommunity,
CreateCommunity,
UserOperation,
Category,
CommunityResponse,
CommunityView,
} from "lemmy-js-client";
@ -28,7 +27,6 @@ import { Icon, Spinner } from "./icon";
interface CommunityFormProps {
community_view?: CommunityView; // If a community is given, that means this is an edit
categories: Category[];
onCancel?(): any;
onCreate?(community: CommunityView): any;
onEdit?(community: CommunityView): any;
@ -51,7 +49,6 @@ export class CommunityForm extends Component<
communityForm: {
name: null,
title: null,
category_id: this.props.categories[0].id,
nsfw: false,
icon: null,
banner: null,
@ -80,7 +77,6 @@ export class CommunityForm extends Component<
this.state.communityForm = {
name: cv.community.name,
title: cv.community.title,
category_id: cv.category.id,
description: cv.community.description,
nsfw: cv.community.nsfw,
icon: cv.community.icon,
@ -205,23 +201,6 @@ export class CommunityForm extends Component<
/>
</div>
</div>
<div class="form-group row">
<label class="col-12 col-form-label" htmlFor="community-category">
{i18n.t("category")}
</label>
<div class="col-12">
<select
class="form-control"
id="community-category"
value={this.state.communityForm.category_id}
onInput={linkEvent(this, this.handleCommunityCategoryChange)}
>
{this.props.categories.map(category => (
<option value={category.id}>{category.name}</option>
))}
</select>
</div>
</div>
{this.props.enableNsfw && (
<div class="form-group row">
@ -304,11 +283,6 @@ export class CommunityForm extends Component<
this.setState(this.state);
}
handleCommunityCategoryChange(i: CommunityForm, event: any) {
i.state.communityForm.category_id = Number(event.target.value);
i.setState(i.state);
}
handleCommunityNsfwChange(i: CommunityForm, event: any) {
i.state.communityForm.nsfw = event.target.checked;
i.setState(i.state);

View file

@ -19,8 +19,6 @@ import {
GetCommentsResponse,
CommentResponse,
GetSiteResponse,
Category,
ListCategoriesResponse,
} from "lemmy-js-client";
import { UserService, WebSocketService } from "../services";
import { PostListings } from "./post-listings";
@ -72,7 +70,6 @@ interface State {
dataType: DataType;
sort: SortType;
page: number;
categories: Category[];
}
interface CommunityProps {
@ -103,7 +100,6 @@ export class Community extends Component<any, State> {
sort: getSortTypeFromProps(this.props),
page: getPageFromProps(this.props),
siteRes: this.isoData.site_res,
categories: [],
};
constructor(props: any, context: any) {
@ -124,14 +120,12 @@ export class Community extends Component<any, State> {
} else {
this.state.comments = this.isoData.routeData[1].comments;
}
this.state.categories = this.isoData.routeData[2].categories;
this.state.communityLoading = false;
this.state.postsLoading = false;
this.state.commentsLoading = false;
} else {
this.fetchCommunity();
this.fetchData();
WebSocketService.Instance.send(wsClient.listCategories());
}
setupTippy();
}
@ -211,8 +205,6 @@ export class Community extends Component<any, State> {
promises.push(req.client.getComments(getCommentsForm));
}
promises.push(req.client.listCategories());
return promises;
}
@ -268,7 +260,6 @@ export class Community extends Component<any, State> {
admins={this.state.siteRes.admins}
online={this.state.communityRes.online}
enableNsfw={this.state.siteRes.site_view.site.enable_nsfw}
categories={this.state.categories}
/>
</div>
</div>
@ -541,10 +532,6 @@ export class Community extends Component<any, State> {
let data = wsJsonToRes<CommentResponse>(msg).data;
createCommentLikeRes(data.comment_view, this.state.comments);
this.setState(this.state);
} else if (op == UserOperation.ListCategories) {
let data = wsJsonToRes<ListCategoriesResponse>(msg).data;
this.state.categories = data.categories;
this.setState(this.state);
}
}
}

View file

@ -5,27 +5,19 @@ import { HtmlTags } from "./html-tags";
import { Spinner } from "./icon";
import {
CommunityView,
UserOperation,
SiteView,
ListCategoriesResponse,
Category,
} from "lemmy-js-client";
import {
setIsoData,
toast,
wsJsonToRes,
wsSubscribe,
isBrowser,
wsUserOp,
wsClient,
} from "../utils";
import { WebSocketService, UserService } from "../services";
import { UserService } from "../services";
import { i18n } from "../i18next";
import { InitialFetchRequest } from "shared/interfaces";
interface CreateCommunityState {
site_view: SiteView;
categories: Category[];
loading: boolean;
}
@ -34,7 +26,6 @@ export class CreateCommunity extends Component<any, CreateCommunityState> {
private subscription: Subscription;
private emptyState: CreateCommunityState = {
site_view: this.isoData.site_res.site_view,
categories: [],
loading: true,
};
constructor(props: any, context: any) {
@ -52,10 +43,7 @@ export class CreateCommunity extends Component<any, CreateCommunityState> {
// Only fetch the data if coming from another route
if (this.isoData.path == this.context.router.route.match.url) {
this.state.categories = this.isoData.routeData[0].categories;
this.state.loading = false;
} else {
WebSocketService.Instance.send(wsClient.listCategories());
}
}
@ -85,7 +73,6 @@ export class CreateCommunity extends Component<any, CreateCommunityState> {
<div class="col-12 col-lg-6 offset-lg-3 mb-4">
<h5>{i18n.t("create_community")}</h5>
<CommunityForm
categories={this.state.categories}
onCreate={this.handleCommunityCreate}
enableNsfw={this.state.site_view.site.enable_nsfw}
/>
@ -100,20 +87,10 @@ export class CreateCommunity extends Component<any, CreateCommunityState> {
this.props.history.push(`/c/${cv.community.name}`);
}
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
return [req.client.listCategories()];
}
parseMessage(msg: any) {
let op = wsUserOp(msg);
if (msg.error) {
// Toast errors are already handled by community-form
return;
} else if (op == UserOperation.ListCategories) {
let data = wsJsonToRes<ListCategoriesResponse>(msg).data;
this.state.categories = data.categories;
this.state.loading = false;
this.setState(this.state);
}
}
}

View file

@ -21,8 +21,6 @@ import {
SearchResponse,
GetSiteResponse,
GetCommunityResponse,
ListCategoriesResponse,
Category,
} from "lemmy-js-client";
import {
CommentSortType,
@ -74,7 +72,6 @@ interface PostState {
loading: boolean;
crossPosts: PostView[];
siteRes: GetSiteResponse;
categories: Category[];
}
export class Post extends Component<any, PostState> {
@ -91,7 +88,6 @@ export class Post extends Component<any, PostState> {
loading: true,
crossPosts: [],
siteRes: this.isoData.site_res,
categories: [],
};
constructor(props: any, context: any) {
@ -109,7 +105,6 @@ export class Post extends Component<any, PostState> {
this.state.postRes.comments,
this.state.commentSort
);
this.state.categories = this.isoData.routeData[1].categories;
this.state.loading = false;
if (isBrowser()) {
@ -120,7 +115,6 @@ export class Post extends Component<any, PostState> {
}
} else {
this.fetchPost();
WebSocketService.Instance.send(wsClient.listCategories());
}
}
@ -158,7 +152,6 @@ export class Post extends Component<any, PostState> {
setOptionalAuth(postForm, req.auth);
promises.push(req.client.getPost(postForm));
promises.push(req.client.listCategories());
return promises;
}
@ -402,7 +395,6 @@ export class Post extends Component<any, PostState> {
online={this.state.postRes.online}
enableNsfw={this.state.siteRes.site_view.site.enable_nsfw}
showIcon
categories={this.state.categories}
/>
</div>
);
@ -570,10 +562,6 @@ export class Post extends Component<any, PostState> {
this.state.postRes.post_view.community = data.community_view.community;
this.state.postRes.moderators = data.moderators;
this.setState(this.state);
} else if (op == UserOperation.ListCategories) {
let data = wsJsonToRes<ListCategoriesResponse>(msg).data;
this.state.categories = data.categories;
this.setState(this.state);
}
}
}

View file

@ -8,7 +8,6 @@ import {
RemoveCommunity,
UserViewSafe,
AddModToCommunity,
Category,
} from "lemmy-js-client";
import { WebSocketService, UserService } from "../services";
import { mdToHtml, getUnixTime, wsClient, authField } from "../utils";
@ -21,7 +20,6 @@ import { i18n } from "../i18next";
interface SidebarProps {
community_view: CommunityView;
categories: Category[];
moderators: CommunityModeratorView[];
admins: UserViewSafe[];
online: number;
@ -60,7 +58,6 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
this.sidebar()
) : (
<CommunityForm
categories={this.props.categories}
community_view={this.props.community_view}
onEdit={this.handleEditCommunity}
onCancel={this.handleEditCancel}
@ -209,11 +206,6 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
count: counts.comments,
})}
</li>
<li className="list-inline-item">
<Link className="badge badge-secondary" to="/communities">
{community_view.category.name}
</Link>
</li>
<li className="list-inline-item">
<Link
className="badge badge-secondary"

View file

@ -45,7 +45,6 @@ export const routes: IRoutePropsWithFetch[] = [
{
path: `/create_community`,
component: CreateCommunity,
fetchInitialData: req => CreateCommunity.fetchInitialData(req),
},
{
path: `/create_private_message/recipient/:recipient_id`,

View file

@ -5022,10 +5022,10 @@ lcid@^1.0.0:
dependencies:
invert-kv "^1.0.0"
lemmy-js-client@0.9.9:
version "0.9.9"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.9.9.tgz#cd1effe165147d04da93d1265e30dd1daf09c0de"
integrity sha512-+tHghqb02WM/Deizneg/8wO6W6ZqG67y5gZwZb9QQLDcowLZWTmFCwdoYVxLxcH6LBmZ1TvPq7ppumB5vQI1qg==
lemmy-js-client@0.10.0-rc.1:
version "0.10.0-rc.1"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.10.0-rc.1.tgz#4a9b9db8fcc8229d634920d7e66f63ab5db8b28e"
integrity sha512-18TQO+EpE+mgCWSwynfFvDCASUjzTkr73/CbneMMHcqexq2R4donE+pNDFFSDHOeYIbdna0f4GZEJhyeh6826g==
levn@^0.4.1:
version "0.4.1"