]> Untitled Git - lemmy.git/commitdiff
Local timeline (#1111)
authorDessalines <dessalines@users.noreply.github.com>
Thu, 3 Sep 2020 13:58:33 +0000 (09:58 -0400)
committerGitHub <noreply@github.com>
Thu, 3 Sep 2020 13:58:33 +0000 (09:58 -0400)
* Adding a local filter. Fixes #1103

* Not showing local if there are no federated instances.

server/lemmy_db/src/comment_view.rs
server/lemmy_db/src/lib.rs
server/lemmy_db/src/post_view.rs
ui/package.json
ui/src/components/listing-type-select.tsx
ui/src/components/main.tsx
ui/src/components/user.tsx
ui/translations/en.json
ui/yarn.lock

index 1dcdf1934ad5d4b45e9d1857ab07373d2b68d2ea..a1751ca679a4b43cb892d102be4e544a120463d9 100644 (file)
@@ -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));
index bf7d00cabb31f704ec26dab3039bfdd77895bb7f..4a4748ce562d2a21154bfc6c39f52a8109d35ea2 100644 (file)
@@ -147,6 +147,7 @@ pub enum SortType {
 #[derive(EnumString, ToString, Debug, Serialize, Deserialize)]
 pub enum ListingType {
   All,
+  Local,
   Subscribed,
   Community,
 }
index d792538360faac6a17948187cbbf799b778c8d30..eb2429c6fe7c82362b0a3fd5664e5b85f2057ce9 100644 (file)
@@ -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));
index f50f061f1789d5145eae060886e2d1da393b76e4..76920d184a90e2f030d2687619e3ad94e0c8c23c 100644 (file)
@@ -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",
index 3d12d43439e661b5e841f0f886657362562fd511..f7d8cc3b2acd477eb6bff1bb8d8f42c9200ab816 100644 (file)
@@ -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')}
         </label>
+        {this.props.showLocal && (
+          <label
+            className={`pointer btn btn-outline-secondary ${
+              this.state.type_ == ListingType.Local && 'active'
+            }`}
+          >
+            <input
+              id={`${this.id}-local`}
+              type="radio"
+              value={ListingType.Local}
+              checked={this.state.type_ == ListingType.Local}
+              onChange={linkEvent(this, this.handleTypeChange)}
+            />
+            {i18n.t('local')}
+          </label>
+        )}
         <label
           className={`pointer btn btn-outline-secondary ${
             this.state.type_ == ListingType.All && 'active'
index 0f4b7da02d213052ad869743395b9f1a3c584af6..286e84ca4c5e7596c4da8ebcd5b29e8a91c5c957 100644 (file)
@@ -537,6 +537,10 @@ export class Main extends Component<any, MainState> {
         <span class="mr-3">
           <ListingTypeSelect
             type_={this.state.listingType}
+            showLocal={
+              this.state.siteRes.federated_instances &&
+              this.state.siteRes.federated_instances.length > 0
+            }
             onChange={this.handleListingTypeChange}
           />
         </span>
index e4b6c750b570a74c6f5dc0032a5a7f3e78b44f89..d7b00ec55bdde91d6638d17cc01a9f082b0da8e2 100644 (file)
@@ -539,6 +539,10 @@ export class User extends Component<any, UserState> {
                       this.state.userSettingsForm.default_listing_type
                     ]
                   }
+                  showLocal={
+                    this.state.siteRes.federated_instances &&
+                    this.state.siteRes.federated_instances.length > 0
+                  }
                   onChange={this.handleUserSettingsListingTypeChange}
                 />
               </form>
index de1fc8268baba5bec10e0d93ae7460c3a0810b0e..e7aa4b315b8dd631808239a8a80e39ef0f499d1f 100644 (file)
     "month": "Month",
     "year": "Year",
     "all": "All",
+    "local": "Local",
     "top": "Top",
     "api": "API",
     "docs": "Docs",
index a474636ed71510010d8c383dbec6f77355e151fe..b50cf07828149ea0e2af148869630850feb11168 100644 (file)
@@ -4938,10 +4938,10 @@ lego-api@^1.0.7:
   dependencies:
     chain-able "^3.0.0"
 
-lemmy-js-client@^1.0.8:
-  version "1.0.8"
-  resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-1.0.8.tgz#98e34c8e3cd07427f883f60fad376dc4d6f46e7f"
-  integrity sha512-YZxD3+8RGz7cRKdI8EIe5iQqQIMm5WzdNz6zZ7/CdkMtXUv6YuMOEv8HLTvBoGuaWIJwlMJ+23NIarxlT26IEw==
+lemmy-js-client@^1.0.9:
+  version "1.0.9"
+  resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-1.0.9.tgz#23cab713613612a524085d6bb3fc1d4042d262a8"
+  integrity sha512-QJc4d1HkSxjv555yH3MAOYbTfgbhmmvvuC1uhFvPwBlL5B5MTry/fWPRbtLfkYTxdZWftE+PYvLVKPr3/dFmxw==
 
 leven@^3.1.0:
   version "3.1.0"
@@ -7017,6 +7017,11 @@ regexpu-core@^4.1.3:
     unicode-match-property-ecmascript "^1.0.4"
     unicode-match-property-value-ecmascript "^1.2.0"
 
+register-service-worker@^1.7.1:
+  version "1.7.1"
+  resolved "https://registry.yarnpkg.com/register-service-worker/-/register-service-worker-1.7.1.tgz#6308347ac6c0af0f6c0b22ea5d59d25e836bc932"
+  integrity sha512-IdTfUZ4u8iJL8o1w8es8l6UMGPmkwHolUdT+UmM1UypC80IB4KbpuIlvwWVj8UDS7eJwkEYRcKRgfRX+oTmJsw==
+
 registry-auth-token@^3.0.1:
   version "3.4.0"
   resolved "https://registry.yarnpkg.com/registry-auth-token/-/registry-auth-token-3.4.0.tgz#d7446815433f5d5ed6431cd5dca21048f66b397e"