From 2aaf4228ac958739abb0c9cb29d00fbb4f80b556 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 3 Sep 2020 09:58:33 -0400 Subject: [PATCH] Local timeline (#1111) * Adding a local filter. Fixes #1103 * Not showing local if there are no federated instances. --- server/lemmy_db/src/comment_view.rs | 8 +++++--- server/lemmy_db/src/lib.rs | 1 + server/lemmy_db/src/post_view.rs | 8 +++++--- ui/package.json | 2 +- ui/src/components/listing-type-select.tsx | 18 ++++++++++++++++++ ui/src/components/main.tsx | 4 ++++ ui/src/components/user.tsx | 4 ++++ ui/translations/en.json | 1 + ui/yarn.lock | 13 +++++++++---- 9 files changed, 48 insertions(+), 11 deletions(-) diff --git a/server/lemmy_db/src/comment_view.rs b/server/lemmy_db/src/comment_view.rs index 1dcdf1934..a1751ca67 100644 --- a/server/lemmy_db/src/comment_view.rs +++ b/server/lemmy_db/src/comment_view.rs @@ -241,9 +241,11 @@ impl<'a> CommentQueryBuilder<'a> { query = query.filter(content.ilike(fuzzy_search(&search_term))); }; - if let ListingType::Subscribed = self.listing_type { - query = query.filter(subscribed.eq(true)); - } + query = match self.listing_type { + ListingType::Subscribed => query.filter(subscribed.eq(true)), + ListingType::Local => query.filter(community_local.eq(true)), + _ => query, + }; if self.saved_only { query = query.filter(saved.eq(true)); diff --git a/server/lemmy_db/src/lib.rs b/server/lemmy_db/src/lib.rs index bf7d00cab..4a4748ce5 100644 --- a/server/lemmy_db/src/lib.rs +++ b/server/lemmy_db/src/lib.rs @@ -147,6 +147,7 @@ pub enum SortType { #[derive(EnumString, ToString, Debug, Serialize, Deserialize)] pub enum ListingType { All, + Local, Subscribed, Community, } diff --git a/server/lemmy_db/src/post_view.rs b/server/lemmy_db/src/post_view.rs index d79253836..eb2429c6f 100644 --- a/server/lemmy_db/src/post_view.rs +++ b/server/lemmy_db/src/post_view.rs @@ -267,9 +267,11 @@ impl<'a> PostQueryBuilder<'a> { let mut query = self.query; - if let ListingType::Subscribed = self.listing_type { - query = query.filter(subscribed.eq(true)); - } + query = match self.listing_type { + ListingType::Subscribed => query.filter(subscribed.eq(true)), + ListingType::Local => query.filter(community_local.eq(true)), + _ => query, + }; if let Some(for_community_id) = self.for_community_id { query = query.filter(community_id.eq(for_community_id)); diff --git a/ui/package.json b/ui/package.json index f50f061f1..76920d184 100644 --- a/ui/package.json +++ b/ui/package.json @@ -37,7 +37,7 @@ "inferno-router": "^7.4.2", "js-cookie": "^2.2.0", "jwt-decode": "^2.2.0", - "lemmy-js-client": "^1.0.8", + "lemmy-js-client": "^1.0.9", "markdown-it": "^11.0.0", "markdown-it-container": "^3.0.0", "markdown-it-emoji": "^1.4.0", diff --git a/ui/src/components/listing-type-select.tsx b/ui/src/components/listing-type-select.tsx index 3d12d4343..f7d8cc3b2 100644 --- a/ui/src/components/listing-type-select.tsx +++ b/ui/src/components/listing-type-select.tsx @@ -6,6 +6,7 @@ import { i18n } from '../i18next'; interface ListingTypeSelectProps { type_: ListingType; + showLocal?: boolean; onChange?(val: ListingType): any; } @@ -31,6 +32,7 @@ export class ListingTypeSelect extends Component< static getDerivedStateFromProps(props: any): ListingTypeSelectProps { return { type_: props.type_, + showLocal: props.showLocal, }; } @@ -53,6 +55,22 @@ export class ListingTypeSelect extends Component< /> {i18n.t('subscribed')} + {this.props.showLocal && ( + + )}