Add bookmarl_category_needed setting

This commit is contained in:
KMY 2023-08-26 18:27:17 +09:00
parent bd0e2bd796
commit 5a961cc368
13 changed files with 66 additions and 8 deletions

View file

@ -1,6 +1,10 @@
import { bookmarkCategoryNeeded } from 'mastodon/initial_state';
import { makeGetStatus } from 'mastodon/selectors';
import api, { getLinks } from '../api';
import { importFetchedStatuses } from './importer';
import { unbookmark } from './interactions';
export const BOOKMARK_CATEGORY_FETCH_REQUEST = 'BOOKMARK_CATEGORY_FETCH_REQUEST';
export const BOOKMARK_CATEGORY_FETCH_SUCCESS = 'BOOKMARK_CATEGORY_FETCH_SUCCESS';
@ -330,7 +334,17 @@ export const addToBookmarkCategoryAdder = bookmarkCategoryId => (dispatch, getSt
};
export const removeFromBookmarkCategoryAdder = bookmarkCategoryId => (dispatch, getState) => {
dispatch(removeFromBookmarkCategory(bookmarkCategoryId, getState().getIn(['bookmarkCategoryAdder', 'statusId'])));
if (bookmarkCategoryNeeded) {
const categories = getState().getIn(['bookmarkCategoryAdder', 'bookmarkCategories', 'items']);
if (categories && categories.count() <= 1) {
const status = makeGetStatus()(getState(), { id: getState().getIn(['bookmarkCategoryAdder', 'statusId']) });
dispatch(unbookmark(status));
} else {
dispatch(removeFromBookmarkCategory(bookmarkCategoryId, getState().getIn(['bookmarkCategoryAdder', 'statusId'])));
}
} else {
dispatch(removeFromBookmarkCategory(bookmarkCategoryId, getState().getIn(['bookmarkCategoryAdder', 'statusId'])));
}
};
export function expandBookmarkCategoryStatuses(bookmarkCategoryId) {

View file

@ -12,7 +12,7 @@ import { PERMISSION_MANAGE_USERS, PERMISSION_MANAGE_FEDERATION } from 'mastodon/
import DropdownMenuContainer from '../containers/dropdown_menu_container';
import EmojiPickerDropdown from '../features/compose/containers/emoji_picker_dropdown_container';
import { me } from '../initial_state';
import { bookmarkCategoryNeeded, me } from '../initial_state';
import { IconButton } from './icon_button';
@ -166,13 +166,21 @@ class StatusActionBar extends ImmutablePureComponent {
};
handleBookmarkClick = () => {
this.props.onBookmark(this.props.status);
if (bookmarkCategoryNeeded) {
this.handleBookmarkCategoryAdderClick();
} else {
this.props.onBookmark(this.props.status);
}
};
handleBookmarkCategoryAdderClick = () => {
this.props.onBookmarkCategoryAdder(this.props.status);
};
handleBookmarkClickOriginal = () => {
this.props.onBookmark(this.props.status);
};
handleDeleteClick = () => {
this.props.onDelete(this.props.status, this.context.router.history);
};
@ -305,7 +313,7 @@ class StatusActionBar extends ImmutablePureComponent {
menu.push({ text: intl.formatMessage(messages.reference), action: this.handleReference });
}
menu.push({ text: intl.formatMessage(status.get('bookmarked') ? messages.removeBookmark : messages.bookmark), action: this.handleBookmarkClick });
menu.push({ text: intl.formatMessage(status.get('bookmarked') ? messages.removeBookmark : messages.bookmark), action: this.handleBookmarkClickOriginal });
menu.push({ text: intl.formatMessage(messages.bookmarkCategory), action: this.handleBookmarkCategoryAdderClick });
if (writtenByMe && pinnableStatus) {

View file

@ -12,7 +12,7 @@ import { PERMISSION_MANAGE_USERS, PERMISSION_MANAGE_FEDERATION } from 'mastodon/
import { IconButton } from '../../../components/icon_button';
import DropdownMenuContainer from '../../../containers/dropdown_menu_container';
import { me } from '../../../initial_state';
import { bookmarkCategoryNeeded, me } from '../../../initial_state';
import EmojiPickerDropdown from '../../compose/containers/emoji_picker_dropdown_container';
const messages = defineMessages({
@ -107,7 +107,11 @@ class ActionBar extends PureComponent {
};
handleBookmarkClick = (e) => {
this.props.onBookmark(this.props.status, e);
if (bookmarkCategoryNeeded) {
this.props.onBookmarkCategoryAdder(this.props.status);
} else {
this.props.onBookmark(this.props.status, e);
}
};
handleDeleteClick = () => {

View file

@ -63,7 +63,7 @@ import {
import ColumnHeader from '../../components/column_header';
import { textForScreenReader, defaultMediaVisibility } from '../../components/status';
import StatusContainer from '../../containers/status_container';
import { boostModal, deleteModal } from '../../initial_state';
import { bookmarkCategoryNeeded, boostModal, deleteModal } from '../../initial_state';
import { makeGetStatus, makeGetPictureInPicture } from '../../selectors';
import Column from '../ui/components/column';
import { attachFullscreenListener, detachFullscreenListener, isFullscreen } from '../ui/util/fullscreen';
@ -367,6 +367,11 @@ class Status extends ImmutablePureComponent {
};
handleBookmarkClick = (status) => {
if (bookmarkCategoryNeeded) {
this.handleBookmarkCategoryAdderClick(status);
return;
}
if (status.get('bookmarked')) {
this.props.dispatch(unbookmark(status));
} else {

View file

@ -50,6 +50,7 @@
* @property {boolean} auto_play_gif
* @property {boolean} activity_api_enabled
* @property {string} admin
* @property {boolean} bookmark_category_needed
* @property {boolean=} boost_modal
* @property {boolean=} delete_modal
* @property {boolean=} disable_swiping
@ -113,6 +114,7 @@ const getMeta = (prop) => initialState?.meta && initialState.meta[prop];
export const activityApiEnabled = getMeta('activity_api_enabled');
export const autoPlayGif = getMeta('auto_play_gif');
export const bookmarkCategoryNeeded = getMeta('bookmark_category_needed');
export const boostModal = getMeta('boost_modal');
export const deleteModal = getMeta('delete_modal');
export const disableSwiping = getMeta('disable_swiping');

View file

@ -20,7 +20,14 @@ import {
const initialState = ImmutableMap();
const normalizeBookmarkCategory = (state, category) => state.set(category.id, fromJS(category));
const normalizeBookmarkCategory = (state, category) => {
const old = state.get(category.id);
state = state.set(category.id, fromJS(category));
if (old) {
state = state.setIn([category.id, 'items'], old.get('items'));
}
return state;
};
const normalizeBookmarkCategories = (state, bookmarkCategories) => {
bookmarkCategories.forEach(bookmarkCategory => {

View file

@ -9,6 +9,9 @@ import {
BOOKMARK_CATEGORY_EDITOR_ADD_SUCCESS,
BOOKMARK_CATEGORY_EDITOR_REMOVE_SUCCESS,
} from '../actions/bookmark_categories';
import {
UNBOOKMARK_SUCCESS,
} from '../actions/interactions';
const initialState = ImmutableMap({
statusId: null,
@ -42,6 +45,8 @@ export default function bookmarkCategoryAdderReducer(state = initialState, actio
return state.updateIn(['bookmarkCategories', 'items'], bookmarkCategory => bookmarkCategory.unshift(action.bookmarkCategoryId));
case BOOKMARK_CATEGORY_EDITOR_REMOVE_SUCCESS:
return state.updateIn(['bookmarkCategories', 'items'], bookmarkCategory => bookmarkCategory.filterNot(item => item === action.bookmarkCategoryId));
case UNBOOKMARK_SUCCESS:
return action.status.get('id') === state.get('statusId') ? state.setIn(['bookmarkCategories', 'items'], ImmutableList()) : state;
default:
return state;
}