From 17ecde6a6e5465112c2e7ba95a23111a3f065a33 Mon Sep 17 00:00:00 2001 From: noellabo Date: Mon, 29 Aug 2022 17:22:23 +0900 Subject: [PATCH] Add reload button for iOS --- .../settings/preferences_controller.rb | 1 + .../mastodon/components/reload_zone.js | 32 +++++++++++++++++++ .../mastodon/components/status_list.js | 11 +++++++ app/javascript/mastodon/initial_state.js | 1 + app/javascript/mastodon/locales/en.json | 1 + app/javascript/mastodon/locales/ja.json | 1 + app/lib/user_settings_decorator.rb | 5 +++ app/models/user.rb | 1 + app/serializers/initial_state_serializer.rb | 3 +- .../settings/preferences/other/show.html.haml | 3 ++ config/locales/simple_form.en.yml | 2 ++ config/locales/simple_form.ja.yml | 2 ++ config/settings.yml | 1 + 13 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 app/javascript/mastodon/components/reload_zone.js diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb index d9a51a38c..ea93d8ca1 100644 --- a/app/controllers/settings/preferences_controller.rb +++ b/app/controllers/settings/preferences_controller.rb @@ -94,6 +94,7 @@ class Settings::PreferencesController < Settings::BaseController :setting_hide_bot_on_public_timeline, :setting_confirm_follow_from_bot, :setting_default_search_searchability, + :setting_show_reload_button, notification_emails: %i(follow follow_request reblog favourite emoji_reaction status_reference mention digest report pending_account trending_tag), interactions: %i(must_be_follower must_be_following must_be_following_dm) ) diff --git a/app/javascript/mastodon/components/reload_zone.js b/app/javascript/mastodon/components/reload_zone.js new file mode 100644 index 000000000..0bc868648 --- /dev/null +++ b/app/javascript/mastodon/components/reload_zone.js @@ -0,0 +1,32 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { injectIntl, defineMessages } from 'react-intl'; +import Icon from 'mastodon/components/icon'; + +const messages = defineMessages({ + reload: { id: 'status.reload', defaultMessage: 'Reload' }, +}); + +export default @injectIntl +class ReloadZone extends React.PureComponent { + + static propTypes = { + onClick: PropTypes.func.isRequired, + intl: PropTypes.object.isRequired, + }; + + handleClick = () => { + this.props.onClick(); + } + + render () { + const { intl } = this.props; + + return ( + + ); + } + +} diff --git a/app/javascript/mastodon/components/status_list.js b/app/javascript/mastodon/components/status_list.js index f8883e5a6..fd6f579c9 100644 --- a/app/javascript/mastodon/components/status_list.js +++ b/app/javascript/mastodon/components/status_list.js @@ -4,9 +4,12 @@ import ImmutablePropTypes from 'react-immutable-proptypes'; import PropTypes from 'prop-types'; import StatusContainer from '../containers/status_container'; import ImmutablePureComponent from 'react-immutable-pure-component'; +import ReloadZone from './reload_zone'; import LoadGap from './load_gap'; import ScrollableList from './scrollable_list'; import RegenerationIndicator from 'mastodon/components/regeneration_indicator'; +import { isIOS } from 'mastodon/is_mobile'; +import { showReloadButton } from '../initial_state'; export default class StatusList extends ImmutablePureComponent { @@ -59,6 +62,10 @@ export default class StatusList extends ImmutablePureComponent { this.props.onLoadMore(this.props.statusIds.size > 0 ? this.props.statusIds.last() : undefined); }, 300, { leading: true }) + handleReload = () => { + location.reload(); + } + _selectChild (index, align_top) { const container = this.node.node; const element = container.querySelector(`article:nth-of-type(${index + 1}) .focusable`); @@ -122,6 +129,10 @@ export default class StatusList extends ImmutablePureComponent { )).concat(scrollableContent); } + if (showReloadButton && scrollableContent && isIOS()) { + scrollableContent = scrollableContent.unshift(); + } + return ( {scrollableContent} diff --git a/app/javascript/mastodon/initial_state.js b/app/javascript/mastodon/initial_state.js index 7f73a214a..f7079d5b3 100644 --- a/app/javascript/mastodon/initial_state.js +++ b/app/javascript/mastodon/initial_state.js @@ -51,5 +51,6 @@ export const enableStatusReference = getMeta('enable_status_reference'); export const maxReferences = initialState?.status_references?.max_references; export const matchVisibilityOfReferences = getMeta('match_visibility_of_references'); export const enableEmptyColumn = getMeta('enable_empty_column'); +export const showReloadButton = getMeta('show_reload_button'); export default initialState; diff --git a/app/javascript/mastodon/locales/en.json b/app/javascript/mastodon/locales/en.json index de6e68ed2..d478375c1 100644 --- a/app/javascript/mastodon/locales/en.json +++ b/app/javascript/mastodon/locales/en.json @@ -550,6 +550,7 @@ "status.redraft": "Delete & re-draft", "status.reference": "Reference", "status.referred_by": "Referred", + "status.reload": "Reload", "status.remove_bookmark": "Remove bookmark", "status.reply": "Reply", "status.replyAll": "Reply to thread", diff --git a/app/javascript/mastodon/locales/ja.json b/app/javascript/mastodon/locales/ja.json index 39542e064..848ab6a93 100644 --- a/app/javascript/mastodon/locales/ja.json +++ b/app/javascript/mastodon/locales/ja.json @@ -550,6 +550,7 @@ "status.redraft": "削除して下書きに戻す", "status.reference": "参照", "status.referred_by": "参照", + "status.reload": "再読み込み", "status.remove_bookmark": "ブックマークを削除", "status.reply": "返信", "status.replyAll": "全員に返信", diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb index 007db1137..243ec1577 100644 --- a/app/lib/user_settings_decorator.rb +++ b/app/lib/user_settings_decorator.rb @@ -88,6 +88,7 @@ class UserSettingsDecorator user.settings['hide_bot_on_public_timeline'] = hide_bot_on_public_timeline_preference if change?('setting_hide_bot_on_public_timeline') user.settings['confirm_follow_from_bot'] = confirm_follow_from_bot_preference if change?('setting_confirm_follow_from_bot') user.settings['default_search_searchability'] = default_search_searchability_preference if change?('setting_default_search_searchability') + user.settings['show_reload_button'] = show_reload_button_preference if change?('setting_show_reload_button') end def merged_notification_emails @@ -326,6 +327,10 @@ end settings['setting_default_search_searchability'] end + def show_reload_button_preference + boolean_cast_setting 'setting_show_reload_button' + end + def boolean_cast_setting(key) ActiveModel::Type::Boolean.new.cast(settings[key]) end diff --git a/app/models/user.rb b/app/models/user.rb index 8f045d427..9a0e3de7a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -142,6 +142,7 @@ class User < ApplicationRecord :mobile_customize, :mobile_content_font_size, :mobile_info_font_size, :mobile_content_emoji_reaction_size, :hide_bot_on_public_timeline, :confirm_follow_from_bot, :default_search_searchability, + :show_reload_button, to: :settings, prefix: :setting, allow_nil: false diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb index d1adfa5c1..da52345b0 100644 --- a/app/serializers/initial_state_serializer.rb +++ b/app/serializers/initial_state_serializer.rb @@ -70,7 +70,8 @@ class InitialStateSerializer < ActiveModel::Serializer store[:info_font_size] = object.current_account.user.setting_info_font_size store[:content_emoji_reaction_size] = object.current_account.user.setting_content_emoji_reaction_size store[:hide_bot_on_public_timeline] = object.current_account.user.setting_hide_bot_on_public_timeline - store[:confirm_follow_from_bot] = object.current_account.user.setting_confirm_follow_from_bot + store[:confirm_follow_from_bot] = object.current_account.user.setting_confirm_follow_from_bot + store[:show_reload_button] = object.current_account.user.setting_show_reload_button else store[:auto_play_gif] = Setting.auto_play_gif store[:display_media] = Setting.display_media diff --git a/app/views/settings/preferences/other/show.html.haml b/app/views/settings/preferences/other/show.html.haml index 058312ee8..373979545 100644 --- a/app/views/settings/preferences/other/show.html.haml +++ b/app/views/settings/preferences/other/show.html.haml @@ -99,6 +99,9 @@ .fields-group = f.input :setting_confirm_follow_from_bot, as: :boolean, wrapper: :with_label, fedibird_features: true + .fields-group + = f.input :setting_show_reload_button, as: :boolean, wrapper: :with_label, fedibird_features: true + -# .fields-group -# = f.input :setting_show_target, as: :boolean, wrapper: :with_label diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index fd0dc05d7..b42179b61 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -83,6 +83,7 @@ en: setting_show_follow_button_on_timeline: You can easily check the follow status and build a follow list quickly setting_show_navigation_panel: Show the navigation panel at the right end of the advanced UI setting_show_quote_button: Selects whether to display the button on the action bar. It does not enable/disable the citation function. + setting_show_reload_button: Show reload button at the top of the iPhone / iPad timeline setting_show_reply_tree_button: Blue marker for replies to another post, yellow marker for posts with replies, and green marker for both setting_show_subscribe_button_on_timeline: You can easily check the status of your subscriptions and quickly build a subscription list setting_show_tab_bar_label: When adding a list etc. to the tab bar, it is recommended to display the label because it is not possible to distinguish by the icon alone @@ -257,6 +258,7 @@ en: setting_show_follow_button_on_timeline: Show follow button on timeline setting_show_navigation_panel: Show the navigation panel setting_show_quote_button: Show the quote button on the action bar + setting_show_reload_button: Show reload button setting_show_reply_tree_button: Show markers on posts where a reply relationship exists setting_show_subscribe_button_on_timeline: Show subscribe button on timeline setting_show_tab_bar_label: Show labels in the tab bar diff --git a/config/locales/simple_form.ja.yml b/config/locales/simple_form.ja.yml index fc3bb1f8e..907934b3d 100644 --- a/config/locales/simple_form.ja.yml +++ b/config/locales/simple_form.ja.yml @@ -83,6 +83,7 @@ ja: setting_show_follow_button_on_timeline: フォロー状態を確認し易くなり、素早くフォローリストを構築できます setting_show_navigation_panel: 上級者向け UI の右端にナビゲーションパネルを表示します setting_show_quote_button: アクションバーへボタンを表示するかどうかの設定です。引用機能の有効・無効を切り替えるものではありません + setting_show_reload_button: iPhoneとiPadで、タイムラインの最上部に再読み込みボタンを表示します setting_show_reply_tree_button: 別の投稿に対しての返信に青のマーカー、返信のついている投稿に黄色のマーカー、両方の場合は緑のマーカーを表示します setting_show_subscribe_button_on_timeline: 購読状態を確認し易くなり、素早く購読リストを構築できます setting_show_tab_bar_label: リスト等をタブバーに追加する場合、アイコンだけでは区別がつかないので、ラベルを表示することをおすすめします @@ -257,6 +258,7 @@ ja: setting_show_follow_button_on_timeline: タイムライン上にフォローボタンを表示する setting_show_navigation_panel: ナビゲーションパネルを表示する setting_show_quote_button: 引用ボタンをアクションバーに表示する + setting_show_reload_button: 再読み込みボタンを表示する setting_show_reply_tree_button: リプライ関係の存在する投稿にマーカーを表示する setting_show_subscribe_button_on_timeline: タイムライン上に購読ボタンを表示する setting_show_tab_bar_label: タブバーにラベルを表示する diff --git a/config/settings.yml b/config/settings.yml index ecc2d7f96..80e30c0ff 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -107,6 +107,7 @@ defaults: &defaults hide_bot_on_public_timeline: false confirm_follow_from_bot: true default_search_searchability: 'private' + show_reload_button: true development: <<: *defaults