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": "^7.20.0",
"eslint-plugin-prettier": "^3.3.1", "eslint-plugin-prettier": "^3.3.1",
"husky": "^5.1.0", "husky": "^5.1.0",
"lemmy-js-client": "0.9.9", "lemmy-js-client": "0.10.0-rc.1",
"lint-staged": "^10.5.4", "lint-staged": "^10.5.4",
"mini-css-extract-plugin": "^1.3.8", "mini-css-extract-plugin": "^1.3.8",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",

View file

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

View file

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

View file

@ -19,8 +19,6 @@ import {
GetCommentsResponse, GetCommentsResponse,
CommentResponse, CommentResponse,
GetSiteResponse, GetSiteResponse,
Category,
ListCategoriesResponse,
} from "lemmy-js-client"; } from "lemmy-js-client";
import { UserService, WebSocketService } from "../services"; import { UserService, WebSocketService } from "../services";
import { PostListings } from "./post-listings"; import { PostListings } from "./post-listings";
@ -72,7 +70,6 @@ interface State {
dataType: DataType; dataType: DataType;
sort: SortType; sort: SortType;
page: number; page: number;
categories: Category[];
} }
interface CommunityProps { interface CommunityProps {
@ -103,7 +100,6 @@ export class Community extends Component<any, State> {
sort: getSortTypeFromProps(this.props), sort: getSortTypeFromProps(this.props),
page: getPageFromProps(this.props), page: getPageFromProps(this.props),
siteRes: this.isoData.site_res, siteRes: this.isoData.site_res,
categories: [],
}; };
constructor(props: any, context: any) { constructor(props: any, context: any) {
@ -124,14 +120,12 @@ export class Community extends Component<any, State> {
} else { } else {
this.state.comments = this.isoData.routeData[1].comments; this.state.comments = this.isoData.routeData[1].comments;
} }
this.state.categories = this.isoData.routeData[2].categories;
this.state.communityLoading = false; this.state.communityLoading = false;
this.state.postsLoading = false; this.state.postsLoading = false;
this.state.commentsLoading = false; this.state.commentsLoading = false;
} else { } else {
this.fetchCommunity(); this.fetchCommunity();
this.fetchData(); this.fetchData();
WebSocketService.Instance.send(wsClient.listCategories());
} }
setupTippy(); setupTippy();
} }
@ -211,8 +205,6 @@ export class Community extends Component<any, State> {
promises.push(req.client.getComments(getCommentsForm)); promises.push(req.client.getComments(getCommentsForm));
} }
promises.push(req.client.listCategories());
return promises; return promises;
} }
@ -268,7 +260,6 @@ export class Community extends Component<any, State> {
admins={this.state.siteRes.admins} admins={this.state.siteRes.admins}
online={this.state.communityRes.online} online={this.state.communityRes.online}
enableNsfw={this.state.siteRes.site_view.site.enable_nsfw} enableNsfw={this.state.siteRes.site_view.site.enable_nsfw}
categories={this.state.categories}
/> />
</div> </div>
</div> </div>
@ -541,10 +532,6 @@ export class Community extends Component<any, State> {
let data = wsJsonToRes<CommentResponse>(msg).data; let data = wsJsonToRes<CommentResponse>(msg).data;
createCommentLikeRes(data.comment_view, this.state.comments); createCommentLikeRes(data.comment_view, this.state.comments);
this.setState(this.state); 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 { Spinner } from "./icon";
import { import {
CommunityView, CommunityView,
UserOperation,
SiteView, SiteView,
ListCategoriesResponse,
Category,
} from "lemmy-js-client"; } from "lemmy-js-client";
import { import {
setIsoData, setIsoData,
toast, toast,
wsJsonToRes,
wsSubscribe, wsSubscribe,
isBrowser, isBrowser,
wsUserOp,
wsClient,
} from "../utils"; } from "../utils";
import { WebSocketService, UserService } from "../services"; import { UserService } from "../services";
import { i18n } from "../i18next"; import { i18n } from "../i18next";
import { InitialFetchRequest } from "shared/interfaces";
interface CreateCommunityState { interface CreateCommunityState {
site_view: SiteView; site_view: SiteView;
categories: Category[];
loading: boolean; loading: boolean;
} }
@ -34,7 +26,6 @@ export class CreateCommunity extends Component<any, CreateCommunityState> {
private subscription: Subscription; private subscription: Subscription;
private emptyState: CreateCommunityState = { private emptyState: CreateCommunityState = {
site_view: this.isoData.site_res.site_view, site_view: this.isoData.site_res.site_view,
categories: [],
loading: true, loading: true,
}; };
constructor(props: any, context: any) { 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 // Only fetch the data if coming from another route
if (this.isoData.path == this.context.router.route.match.url) { if (this.isoData.path == this.context.router.route.match.url) {
this.state.categories = this.isoData.routeData[0].categories;
this.state.loading = false; 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"> <div class="col-12 col-lg-6 offset-lg-3 mb-4">
<h5>{i18n.t("create_community")}</h5> <h5>{i18n.t("create_community")}</h5>
<CommunityForm <CommunityForm
categories={this.state.categories}
onCreate={this.handleCommunityCreate} onCreate={this.handleCommunityCreate}
enableNsfw={this.state.site_view.site.enable_nsfw} 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}`); this.props.history.push(`/c/${cv.community.name}`);
} }
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
return [req.client.listCategories()];
}
parseMessage(msg: any) { parseMessage(msg: any) {
let op = wsUserOp(msg);
if (msg.error) { if (msg.error) {
// Toast errors are already handled by community-form // Toast errors are already handled by community-form
return; 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, SearchResponse,
GetSiteResponse, GetSiteResponse,
GetCommunityResponse, GetCommunityResponse,
ListCategoriesResponse,
Category,
} from "lemmy-js-client"; } from "lemmy-js-client";
import { import {
CommentSortType, CommentSortType,
@ -74,7 +72,6 @@ interface PostState {
loading: boolean; loading: boolean;
crossPosts: PostView[]; crossPosts: PostView[];
siteRes: GetSiteResponse; siteRes: GetSiteResponse;
categories: Category[];
} }
export class Post extends Component<any, PostState> { export class Post extends Component<any, PostState> {
@ -91,7 +88,6 @@ export class Post extends Component<any, PostState> {
loading: true, loading: true,
crossPosts: [], crossPosts: [],
siteRes: this.isoData.site_res, siteRes: this.isoData.site_res,
categories: [],
}; };
constructor(props: any, context: any) { constructor(props: any, context: any) {
@ -109,7 +105,6 @@ export class Post extends Component<any, PostState> {
this.state.postRes.comments, this.state.postRes.comments,
this.state.commentSort this.state.commentSort
); );
this.state.categories = this.isoData.routeData[1].categories;
this.state.loading = false; this.state.loading = false;
if (isBrowser()) { if (isBrowser()) {
@ -120,7 +115,6 @@ export class Post extends Component<any, PostState> {
} }
} else { } else {
this.fetchPost(); this.fetchPost();
WebSocketService.Instance.send(wsClient.listCategories());
} }
} }
@ -158,7 +152,6 @@ export class Post extends Component<any, PostState> {
setOptionalAuth(postForm, req.auth); setOptionalAuth(postForm, req.auth);
promises.push(req.client.getPost(postForm)); promises.push(req.client.getPost(postForm));
promises.push(req.client.listCategories());
return promises; return promises;
} }
@ -402,7 +395,6 @@ export class Post extends Component<any, PostState> {
online={this.state.postRes.online} online={this.state.postRes.online}
enableNsfw={this.state.siteRes.site_view.site.enable_nsfw} enableNsfw={this.state.siteRes.site_view.site.enable_nsfw}
showIcon showIcon
categories={this.state.categories}
/> />
</div> </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.post_view.community = data.community_view.community;
this.state.postRes.moderators = data.moderators; this.state.postRes.moderators = data.moderators;
this.setState(this.state); 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, RemoveCommunity,
UserViewSafe, UserViewSafe,
AddModToCommunity, AddModToCommunity,
Category,
} from "lemmy-js-client"; } from "lemmy-js-client";
import { WebSocketService, UserService } from "../services"; import { WebSocketService, UserService } from "../services";
import { mdToHtml, getUnixTime, wsClient, authField } from "../utils"; import { mdToHtml, getUnixTime, wsClient, authField } from "../utils";
@ -21,7 +20,6 @@ import { i18n } from "../i18next";
interface SidebarProps { interface SidebarProps {
community_view: CommunityView; community_view: CommunityView;
categories: Category[];
moderators: CommunityModeratorView[]; moderators: CommunityModeratorView[];
admins: UserViewSafe[]; admins: UserViewSafe[];
online: number; online: number;
@ -60,7 +58,6 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
this.sidebar() this.sidebar()
) : ( ) : (
<CommunityForm <CommunityForm
categories={this.props.categories}
community_view={this.props.community_view} community_view={this.props.community_view}
onEdit={this.handleEditCommunity} onEdit={this.handleEditCommunity}
onCancel={this.handleEditCancel} onCancel={this.handleEditCancel}
@ -209,11 +206,6 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
count: counts.comments, count: counts.comments,
})} })}
</li> </li>
<li className="list-inline-item">
<Link className="badge badge-secondary" to="/communities">
{community_view.category.name}
</Link>
</li>
<li className="list-inline-item"> <li className="list-inline-item">
<Link <Link
className="badge badge-secondary" className="badge badge-secondary"

View file

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

View file

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