From e82467ca41f4940add32061ca70214e236cc435f Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Sun, 9 Oct 2022 10:49:51 +0900 Subject: [PATCH] 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 --- .../mastodon/components/server_banner.js | 10 ++-- .../ui/components/navigation_panel.js | 20 ++++--- app/javascript/mastodon/initial_state.js | 58 ++++++++++++++++++- app/serializers/initial_state_serializer.rb | 2 + 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 bdd7f7380b..ae4e200c34 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 7c7c9056fe..a9b80e71db 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 { )} - - + {signedIn || timelinePreview && ( + <> + + + + )} {!signedIn && (
diff --git a/app/javascript/mastodon/initial_state.js b/app/javascript/mastodon/initial_state.js index 9ecbfe5763..031c748cf0 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 1a49182a8e..bec725e1b4 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