Skip to content

Commit

Permalink
Fix a few issues with non-PDF attachments
Browse files Browse the repository at this point in the history
- Fix annotations for non-PDF attachments not being copied to group libraries.
- Report schema used to the API to avoid annotations being rejected due to the `invalidProp` key.
- Improve the label for the option to open a file in the reader on touch devices.
  • Loading branch information
tnajdek committed Nov 22, 2024
1 parent fcccc3d commit 53bf19f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"redux-async-queue": "^1.0.0",
"redux-thunk": "^3.1.0",
"use-debounce": "^10.0.4",
"zotero-api-client": "^0.45.0"
"zotero-api-client": "^0.46.0"
},
"devDependencies": {
"@babel/core": "^7.26.0",
Expand Down
8 changes: 5 additions & 3 deletions src/js/actions/items-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import api from 'zotero-api-client';
import { omit, pick } from 'web-common/utils';

import { extractItems, chunkedAction, PartialWriteError } from '../common/actions';
import { fetchItemsByKeys, fetchChildItems, fetchItemTemplate } from '.';
import { fetchItemsByKeys, fetchAllChildItems, fetchItemTemplate } from '.';
import { fetchLibrarySettings, requestTracker } from '.';
import { get, getItemCanonicalUrl, getUniqueId, removeRelationByItemKey, reverseMap } from '../utils';
import { getFilesData } from '../common/event';
import { getToggledTags, TOGGLE_TOGGLE } from '../common/tags';
import { parseDescriptiveString } from '../common/format';
import { strToISO } from '../common/date';
import { sniffForMIMEType } from '../common/mime';
import { READER_CONTENT_TYPES } from '../constants/reader';

import {
BEGIN_ONGOING,
Expand Down Expand Up @@ -1089,12 +1090,13 @@ const copyToLibrary = (itemKeys, sourceLibraryKey, targetLibraryKey, targetColle
const newItem = newItems[index];
const skipChildItems = newItem.itemType === 'annotation'
|| newItem.linkMode === 'embedded_image'
|| (newItem.itemType === 'attachment' && newItem.contentType !== 'application/pdf');
|| (newItem.itemType === 'attachment' && !Object.keys(READER_CONTENT_TYPES).includes(newItem.contentType));

if (skipChildItems) {
return;
}
await dispatch(fetchChildItems(ik, { start: 0, limit: 100 }, { current: { libraryKey: sourceLibraryKey }}));

await dispatch(fetchAllChildItems(ik, null, { current: { libraryKey: sourceLibraryKey }}));
const childItemsKeys = get(getState(), ['libraries', sourceLibraryKey, 'itemsByParent', ik, 'keys'], []);
if(childItemsKeys && childItemsKeys.length) {
const newChildItemsChunked = await dispatch(chunkedAction(copyToLibrary, childItemsKeys, sourceLibraryKey, targetLibraryKey, [], { parentItem: newItem.key }, depth + 1, aggrMultiPatch));
Expand Down
3 changes: 2 additions & 1 deletion src/js/component/item/actions/more-actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { cleanDOI, cleanURL, get, getDOIURL } from '../../../utils';
import { currentGoToSubscribeUrl, pickBestItemAction } from '../../../actions';
import { useItemActionHandlers } from '../../../hooks';
import { READER_CONTENT_TYPES, READER_CONTENT_TYPES_HUMAN_READABLE } from '../../../constants/reader';

const MoreActionsItems = ({ divider = false }) => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -37,7 +38,7 @@ const MoreActionsItems = ({ divider = false }) => {
<Fragment>
{ isViewFile && (
<DropdownItem onClick={ handleViewFileClick }>
View { attachment.attachmentType === 'application/pdf' ? 'PDF' : 'File' }
View {Object.keys(READER_CONTENT_TYPES).includes(attachment.attachmentType) ? READER_CONTENT_TYPES_HUMAN_READABLE[attachment.attachmentType] : 'File' }
</DropdownItem>
) }
{ isViewOnline && (
Expand Down
6 changes: 6 additions & 0 deletions src/js/constants/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ export const READER_CONTENT_TYPES = {
'application/epub+zip': 'epub',
'text/html': 'snapshot',
};

export const READER_CONTENT_TYPES_HUMAN_READABLE = {
'application/pdf': 'PDF',
'application/epub+zip': 'EPUB',
'text/html': 'Snapshot',
};
10 changes: 9 additions & 1 deletion src/js/reducers/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CONFIGURE, SORT_ITEMS, RECEIVE_GROUPS } from '../constants/actions.js';
import { CONFIGURE, RECEIVE_GROUPS, RECEIVE_SCHEMA } from '../constants/actions.js';
import { sortByKey } from '../utils';
import { pick } from 'web-common/utils';
import * as defaults from '../constants/defaults';
Expand Down Expand Up @@ -63,6 +63,14 @@ const slugify = name => {

const config = (state = defaultState, action) => {
switch(action.type) {
case RECEIVE_SCHEMA:
return {
...state,
apiConfig: {
...state.apiConfig,
zoteroSchemaVersion: action.schema.version
}
}
case CONFIGURE:
action.libraries = action.libraries || {};
return {
Expand Down

0 comments on commit 53bf19f

Please sign in to comment.