* Fix local development.
* Updating translations.
* Adding default site post listing. Fixes #625
-Subproject commit 2e9f6291c91a9c97fa7f7740f90ee3146515e03c
+Subproject commit 1cbac3a1521e26b9b5c1c97a0c9852655ddcf00b
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.4",
"import-sort-style-module": "^6.0.0",
- "lemmy-js-client": "0.16.4-rc.1",
+ "lemmy-js-client": "0.17.0-rc.5",
"lint-staged": "^12.4.1",
"mini-css-extract-plugin": "^2.6.0",
"node-fetch": "^2.6.1",
const extraThemesFolder =
process.env["LEMMY_UI_EXTRA_THEMES_FOLDER"] || "./extra_themes";
-server.use(function (_req, res, next) {
- // in debug mode, websocket backend may be on another port, so we need to permit it in csp policy
- var websocketBackend;
- if (process.env.NODE_ENV == "development") {
- websocketBackend = wsUriBase;
- }
- res.setHeader(
- "Content-Security-Policy",
- `default-src 'none'; connect-src 'self' ${websocketBackend}; img-src * data:; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; form-action 'self'; base-uri 'self'`
- );
- next();
-});
+if (process.env.NODE_ENV !== "development") {
+ server.use(function (_req, res, next) {
+ res.setHeader(
+ "Content-Security-Policy",
+ `default-src 'none'; connect-src 'self' ${wsUriBase}; img-src * data:; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; form-action 'self'; base-uri 'self'`
+ );
+ next();
+ });
+}
server.use(express.json());
server.use(express.urlencoded({ extended: false }));
server.use("/static", express.static(path.resolve("./dist")));
interface ListingTypeSelectProps {
type_: ListingType;
- showLocal?: boolean;
+ showLocal: boolean;
+ showSubscribed: boolean;
onChange?(val: ListingType): any;
}
return {
type_: props.type_,
showLocal: props.showLocal,
+ showSubscribed: props.showSubscribed,
};
}
render() {
return (
<div class="btn-group btn-group-toggle flex-wrap mb-2">
- <label
- title={i18n.t("subscribed_description")}
- className={`btn btn-outline-secondary
+ {this.props.showSubscribed && (
+ <label
+ title={i18n.t("subscribed_description")}
+ className={`btn btn-outline-secondary
${this.state.type_ == ListingType.Subscribed && "active"}
${
UserService.Instance.myUserInfo == undefined
: "pointer"
}
`}
- >
- <input
- id={`${this.id}-subscribed`}
- type="radio"
- value={ListingType.Subscribed}
- checked={this.state.type_ == ListingType.Subscribed}
- onChange={linkEvent(this, this.handleTypeChange)}
- disabled={UserService.Instance.myUserInfo == undefined}
- />
- {i18n.t("subscribed")}
- </label>
+ >
+ <input
+ id={`${this.id}-subscribed`}
+ type="radio"
+ value={ListingType.Subscribed}
+ checked={this.state.type_ == ListingType.Subscribed}
+ onChange={linkEvent(this, this.handleTypeChange)}
+ disabled={UserService.Instance.myUserInfo == undefined}
+ />
+ {i18n.t("subscribed")}
+ </label>
+ )}
{this.props.showLocal && (
<label
title={i18n.t("local_description")}
<ListingTypeSelect
type_={this.state.listingType}
showLocal={showLocal(this.isoData)}
+ showSubscribed
onChange={this.handleListingTypeChange}
/>
</span>
setIsoData,
setOptionalAuth,
setupTippy,
+ showLocal,
toast,
updatePersonBlock,
wsClient,
}
/>
{!cv.community.local && this.state.communityRes.site && (
- <SiteSidebar site={this.state.communityRes.site} />
+ <SiteSidebar
+ site={this.state.communityRes.site}
+ showLocal={showLocal(this.isoData)}
+ />
)}
</>
)}
enableNsfw={this.state.siteRes.site_view.site.enable_nsfw}
/>
{!cv.community.local && this.state.communityRes.site && (
- <SiteSidebar site={this.state.communityRes.site} />
+ <SiteSidebar
+ site={this.state.communityRes.site}
+ showLocal={showLocal(this.isoData)}
+ />
)}
</div>
</div>
isBrowser,
randomStr,
setIsoData,
+ showLocal,
toast,
wsClient,
wsJsonToRes,
path={this.context.router.route.match.url}
/>
{this.state.siteRes.site_view.site.id && (
- <SiteForm site={this.state.siteRes.site_view.site} />
+ <SiteForm
+ site={this.state.siteRes.site_view.site}
+ showLocal={showLocal(this.isoData)}
+ />
)}
{this.admins()}
{this.bannedUsers()}
loading: true,
posts: [],
comments: [],
- listingType: getListingTypeFromProps(this.props),
+ listingType: getListingTypeFromProps(
+ this.props,
+ ListingType[
+ this.isoData.site_res.site_view.site.default_post_listing_type
+ ]
+ ),
dataType: getDataTypeFromProps(this.props),
sort: getSortTypeFromProps(this.props),
page: getPageFromProps(this.props),
static getDerivedStateFromProps(props: any): HomeProps {
return {
- listingType: getListingTypeFromProps(props),
+ listingType: getListingTypeFromProps(props, ListingType.Local),
dataType: getDataTypeFromProps(props),
sort: getSortTypeFromProps(props),
page: getPageFromProps(props),
UserService.Instance.myUserInfo.local_user_view.local_user
.default_listing_type
]
- : ListingType.Local;
+ : null;
let sort: SortType = pathSplit[7]
? SortType[pathSplit[7]]
: UserService.Instance.myUserInfo
page,
limit: fetchLimit,
sort,
- type_,
saved_only: false,
};
+ if (type_) {
+ getPostsForm.type_ = type_;
+ }
+
setOptionalAuth(getPostsForm, req.auth);
promises.push(req.client.getPosts(getPostsForm));
} else {
page,
limit: fetchLimit,
sort,
- type_,
+ type_: type_ || ListingType.Local,
saved_only: false,
};
setOptionalAuth(getCommentsForm, req.auth);
admins={siteRes.admins}
counts={siteRes.site_view.counts}
online={siteRes.online}
+ showLocal={showLocal(this.isoData)}
/>
)}
{this.state.showTrendingMobile && (
admins={siteRes.admins}
counts={siteRes.site_view.counts}
online={siteRes.online}
+ showLocal={showLocal(this.isoData)}
/>
{UserService.Instance.myUserInfo &&
<ListingTypeSelect
type_={this.state.listingType}
showLocal={showLocal(this.isoData)}
+ showSubscribed
onChange={this.handleListingTypeChange}
/>
</span>
page: this.state.page,
limit: fetchLimit,
sort: this.state.sort,
- type_: this.state.listingType,
saved_only: false,
auth: authField(false),
};
+ if (this.state.listingType) {
+ getPostsForm.type_ = this.state.listingType;
+ }
+
WebSocketService.Instance.send(wsClient.getPosts(getPostsForm));
} else {
let getCommentsForm: GetComments = {
{!this.state.doneRegisteringUser ? (
this.registerUser()
) : (
- <SiteForm />
+ <SiteForm showLocal />
)}
</div>
</div>
import { Component, linkEvent } from "inferno";
import { Prompt } from "inferno-router";
-import { CreateSite, EditSite, Site } from "lemmy-js-client";
+import { CreateSite, EditSite, ListingType, Site } from "lemmy-js-client";
import { i18n } from "../../i18next";
import { WebSocketService } from "../../services";
import {
} from "../../utils";
import { Spinner } from "../common/icon";
import { ImageUploadForm } from "../common/image-upload-form";
+import { ListingTypeSelect } from "../common/listing-type-select";
import { MarkdownTextArea } from "../common/markdown-textarea";
interface SiteFormProps {
site?: Site; // If a site is given, that means this is an edit
+ showLocal: boolean;
onCancel?(): any;
onEdit?(): any;
}
application_question: null,
private_instance: null,
default_theme: null,
+ default_post_listing_type: null,
auth: authField(false),
},
loading: false,
this.handleBannerUpload = this.handleBannerUpload.bind(this);
this.handleBannerRemove = this.handleBannerRemove.bind(this);
+ this.handleDefaultPostListingTypeChange =
+ this.handleDefaultPostListingTypeChange.bind(this);
+
if (this.props.site) {
let site = this.props.site;
this.state.siteForm = {
application_question: site.application_question,
private_instance: site.private_instance,
default_theme: site.default_theme,
+ default_post_listing_type: site.default_post_listing_type,
auth: authField(false),
};
}
</select>
</div>
</div>
+ {this.props.showLocal && (
+ <form className="form-group row">
+ <label class="col-sm-3">{i18n.t("listing_type")}</label>
+ <div class="col-sm-9">
+ <ListingTypeSelect
+ type_={
+ ListingType[this.state.siteForm.default_post_listing_type]
+ }
+ showLocal
+ showSubscribed={false}
+ onChange={this.handleDefaultPostListingTypeChange}
+ />
+ </div>
+ </form>
+ )}
<div class="form-group row">
<div class="col-12">
<div class="form-check">
this.state.siteForm.banner = "";
this.setState(this.state);
}
+
+ handleDefaultPostListingTypeChange(val: ListingType) {
+ this.state.siteForm.default_post_listing_type =
+ ListingType[ListingType[val]];
+ this.setState(this.state);
+ }
}
interface SiteSidebarProps {
site: Site;
+ showLocal: boolean;
counts?: SiteAggregates;
admins?: PersonViewSafe[];
online?: number;
) : (
<SiteForm
site={site}
+ showLocal={this.props.showLocal}
onEdit={this.handleEditSite}
onCancel={this.handleEditCancel}
/>
]
}
showLocal={showLocal(this.isoData)}
+ showSubscribed
onChange={this.handleListingTypeChange}
/>
</div>
<ListingTypeSelect
type_={this.state.listingType}
showLocal={showLocal(this.isoData)}
+ showSubscribed
onChange={this.handleListingTypeChange}
/>
</span>
return communities;
}
-export function getListingTypeFromProps(props: any): ListingType {
+export function getListingTypeFromProps(
+ props: any,
+ defaultListingType: ListingType
+): ListingType {
return props.match.params.listing_type
? routeListingTypeToEnum(props.match.params.listing_type)
: UserService.Instance.myUserInfo
UserService.Instance.myUserInfo.local_user_view.local_user
.default_listing_type
]
- : ListingType.Local;
+ : defaultListingType;
}
export function getListingTypeFromPropsNoDefault(props: any): ListingType {
dependencies:
invert-kv "^1.0.0"
-lemmy-js-client@0.16.4-rc.1:
- version "0.16.4-rc.1"
- resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.16.4-rc.1.tgz#dfa94a152a7abe75f50f2599a8d9b40c143f37ff"
- integrity sha512-94Xh7A/WDywRaJ0GPXPaXZhyXqMzK0gAISNSB8m++2mC1WJalOqfjR72q/7PmLGxfjYO88/aWSz4Sk0SXWJjCw==
+lemmy-js-client@0.17.0-rc.5:
+ version "0.17.0-rc.5"
+ resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.5.tgz#8065ddca68acfbccc7a693ae0f31d6ab66dce972"
+ integrity sha512-IuSYaK4//KVFg+s4Av/PaxMM2tQpP3sL6G3zXfzbrZfCEtBp9ZlOEMFAu/neRgNumVh+R/koIwf8iLh4UdYCdg==
levn@^0.4.1:
version "0.4.1"