about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYamagishi Kazutoshi <ykzts@desire.sh>2022-10-09 10:49:51 +0900
committerGitHub <noreply@github.com>2022-10-09 03:49:51 +0200
commite82467ca41f4940add32061ca70214e236cc435f (patch)
tree489877be8e182f6425884ae9f927f2adeea2ddb6
parent45ebdb72ca1678eb30e6087f61bd019c7ea903f4 (diff)
Remove timeline preview link from nav panel when not signed-in (#19320)
* Remove timeline preview link from nav panel when not signed-in

* Always enable server stats
-rw-r--r--app/javascript/mastodon/components/server_banner.js10
-rw-r--r--app/javascript/mastodon/features/ui/components/navigation_panel.js20
-rw-r--r--app/javascript/mastodon/initial_state.js58
-rw-r--r--app/serializers/initial_state_serializer.rb2
4 files changed, 75 insertions, 15 deletions
diff --git a/app/javascript/mastodon/components/server_banner.js b/app/javascript/mastodon/components/server_banner.js
index bdd7f7380..ae4e200c3 100644
--- a/app/javascript/mastodon/components/server_banner.js
+++ b/app/javascript/mastodon/components/server_banner.js
@@ -1,12 +1,12 @@
-import React from 'react';
 import PropTypes from 'prop-types';
-import { domain } from 'mastodon/initial_state';
-import { fetchServer } from 'mastodon/actions/server';
+import React from 'react';
+import { FormattedMessage, defineMessages, injectIntl } from 'react-intl';
 import { connect } from 'react-redux';
-import Account from 'mastodon/containers/account_container';
+import { fetchServer } from 'mastodon/actions/server';
 import ShortNumber from 'mastodon/components/short_number';
 import Skeleton from 'mastodon/components/skeleton';
-import { FormattedMessage, injectIntl, defineMessages } from 'react-intl';
+import Account from 'mastodon/containers/account_container';
+import { domain } from 'mastodon/initial_state';
 
 const messages = defineMessages({
   aboutActiveUsers: { id: 'server_banner.about_active_users', defaultMessage: 'People using this server during the last 30 days (Monthly Active Users)' },
diff --git a/app/javascript/mastodon/features/ui/components/navigation_panel.js b/app/javascript/mastodon/features/ui/components/navigation_panel.js
index 7c7c9056f..a9b80e71d 100644
--- a/app/javascript/mastodon/features/ui/components/navigation_panel.js
+++ b/app/javascript/mastodon/features/ui/components/navigation_panel.js
@@ -1,14 +1,14 @@
-import React from 'react';
 import PropTypes from 'prop-types';
-import { NavLink, Link } from 'react-router-dom';
+import React from 'react';
 import { FormattedMessage } from 'react-intl';
+import { Link, NavLink } from 'react-router-dom';
 import Icon from 'mastodon/components/icon';
-import { showTrends } from 'mastodon/initial_state';
-import NotificationsCounterIcon from './notifications_counter_icon';
+import Logo from 'mastodon/components/logo';
+import TrendsContainer from 'mastodon/features/getting_started/containers/trends_container';
+import { showTrends, timelinePreview } from 'mastodon/initial_state';
 import FollowRequestsNavLink from './follow_requests_nav_link';
 import ListPanel from './list_panel';
-import TrendsContainer from 'mastodon/features/getting_started/containers/trends_container';
-import Logo from 'mastodon/components/logo';
+import NotificationsCounterIcon from './notifications_counter_icon';
 import SignInBanner from './sign_in_banner';
 
 export default class NavigationPanel extends React.Component {
@@ -37,8 +37,12 @@ export default class NavigationPanel extends React.Component {
         )}
 
         <NavLink className='column-link column-link--transparent' to='/explore' data-preview-title-id='explore.title' data-preview-icon='hashtag'><Icon className='column-link__icon' id='hashtag' fixedWidth /><FormattedMessage id='explore.title' defaultMessage='Explore' /></NavLink>
-        <NavLink className='column-link column-link--transparent' to='/public/local' data-preview-title-id='column.community' data-preview-icon='users' ><Icon className='column-link__icon' id='users' fixedWidth /><FormattedMessage id='tabs_bar.local_timeline' defaultMessage='Local' /></NavLink>
-        <NavLink className='column-link column-link--transparent' exact to='/public' data-preview-title-id='column.public' data-preview-icon='globe' ><Icon className='column-link__icon' id='globe' fixedWidth /><FormattedMessage id='tabs_bar.federated_timeline' defaultMessage='Federated' /></NavLink>
+        {signedIn || timelinePreview && (
+          <>
+            <NavLink className='column-link column-link--transparent' to='/public/local' data-preview-title-id='column.community' data-preview-icon='users' ><Icon className='column-link__icon' id='users' fixedWidth /><FormattedMessage id='tabs_bar.local_timeline' defaultMessage='Local' /></NavLink>
+            <NavLink className='column-link column-link--transparent' exact to='/public' data-preview-title-id='column.public' data-preview-icon='globe' ><Icon className='column-link__icon' id='globe' fixedWidth /><FormattedMessage id='tabs_bar.federated_timeline' defaultMessage='Federated' /></NavLink>
+          </>
+        )}
 
         {!signedIn && (
           <div className='navigation-panel__sign-in-banner'>
diff --git a/app/javascript/mastodon/initial_state.js b/app/javascript/mastodon/initial_state.js
index 9ecbfe576..031c748cf 100644
--- a/app/javascript/mastodon/initial_state.js
+++ b/app/javascript/mastodon/initial_state.js
@@ -1,7 +1,59 @@
+// @ts-check
+
+/**
+ * @typedef {[code: string, name: string, localName: string]} InitialStateLanguage
+ */
+
+/**
+ * @typedef InitialStateMeta
+ * @property {string} access_token
+ * @property {boolean=} advanced_layout
+ * @property {boolean} auto_play_gif
+ * @property {boolean} activity_api_enabled
+ * @property {string} admin
+ * @property {boolean=} boost_modal
+ * @property {boolean} crop_images
+ * @property {boolean=} delete_modal
+ * @property {boolean=} disable_swiping
+ * @property {boolean} display_media
+ * @property {string} domain
+ * @property {boolean=} expand_spoilers
+ * @property {boolean} limited_federation_mode
+ * @property {string} locale
+ * @property {string | null} mascot
+ * @property {string=} me
+ * @property {boolean} profile_directory
+ * @property {boolean} registrations_open
+ * @property {boolean} reduce_motion
+ * @property {string} repository
+ * @property {boolean} search_enabled
+ * @property {string} source_url
+ * @property {string} streaming_api_base_url
+ * @property {boolean} timeline_preview
+ * @property {string} title
+ * @property {boolean} trends
+ * @property {boolean} unfollow_modal
+ * @property {boolean} use_blurhash
+ * @property {boolean=} use_pending_items
+ * @property {string} version
+ */
+
+/**
+ * @typedef InitialState
+ * @property {InitialStateLanguage[]} languages
+ * @property {InitialStateMeta} meta
+ */
+
 const element = document.getElementById('initial-state');
+/** @type {InitialState | undefined} */
 const initialState = element && JSON.parse(element.textContent);
 
-const getMeta = (prop) => initialState && initialState.meta && initialState.meta[prop];
+/**
+ * @template {keyof InitialStateMeta} K
+ * @param {K} prop
+ * @returns {InitialStateMeta[K] | undefined}
+ */
+const getMeta = (prop) => initialState?.meta && initialState.meta[prop];
 
 export const domain = getMeta('domain');
 export const reduceMotion = getMeta('reduce_motion');
@@ -27,6 +79,8 @@ export const showTrends = getMeta('trends');
 export const title = getMeta('title');
 export const cropImages = getMeta('crop_images');
 export const disableSwiping = getMeta('disable_swiping');
-export const languages = initialState && initialState.languages;
+export const timelinePreview = getMeta('timeline_preview');
+export const activityApiEnabled = getMeta('activity_api_enabled');
+export const languages = initialState?.languages;
 
 export default initialState;
diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb
index 1a49182a8..bec725e1b 100644
--- a/app/serializers/initial_state_serializer.rb
+++ b/app/serializers/initial_state_serializer.rb
@@ -28,6 +28,8 @@ class InitialStateSerializer < ActiveModel::Serializer
       profile_directory: Setting.profile_directory,
       trends: Setting.trends,
       registrations_open: Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode,
+      timeline_preview: Setting.timeline_preview,
+      activity_api_enabled: Setting.activity_api_enabled,
     }
 
     if object.current_account