Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create favorites files screen #818

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/apps/dms/src/api/document-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const createDocumentCriteria = ({
parentDirectoryId,
noParent,
isDirectory = null,
favoriteFileIds,
}) => {
const criteria = [getSearchCriterias('dms_document', searchValue)];

Expand Down Expand Up @@ -73,6 +74,14 @@ const createDocumentCriteria = ({
});
}

if (Array.isArray(favoriteFileIds) && favoriteFileIds.length > 0) {
criteria.push({
fieldName: 'id',
operator: 'in',
value: favoriteFileIds,
});
}

return criteria;
};

Expand All @@ -82,6 +91,7 @@ export async function searchDocument({
extensions,
parentDirectoryId,
noParent = false,
favoriteFileIds = [],
page = 0,
}) {
return createStandardSearch({
Expand All @@ -92,6 +102,7 @@ export async function searchDocument({
extensions,
parentDirectoryId,
noParent,
favoriteFileIds,
}),
fieldKey: 'dms_document',
sortKey: 'dms_document',
Expand Down
24 changes: 24 additions & 0 deletions packages/apps/dms/src/features/documentSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ export const searchDirectory = createAsyncThunk(
},
);

export const searchFavoriteDocument = createAsyncThunk(
'dms_document/searchFavoriteDocument',
async function (data, {getState}) {
return handlerApiCall({
fetchFunction: _searchDocument,
data,
action: 'Dms_SliceAction_SearchFavoriteDocument',
getState,
responseOptions: {isArrayResponse: true},
});
},
);

const initialState = {
loadingDocuments: false,
moreLoadingDocument: false,
Expand All @@ -62,6 +75,11 @@ const initialState = {
moreLoadingDirectory: false,
isListEndDirectory: false,
directoryList: [],

loadingFavoriteDocument: false,
moreLoadingFavoriteDocument: false,
isListEndFavoriteDocument: false,
favoriteDocumentList: [],
};

const documentSlice = createSlice({
Expand All @@ -80,6 +98,12 @@ const documentSlice = createSlice({
isListEnd: 'isListEndDirectory',
list: 'directoryList',
});
generateInifiniteScrollCases(builder, searchFavoriteDocument, {
loading: 'loadingFavoriteDocument',
moreLoading: 'moreLoadingFavoriteDocument',
isListEnd: 'isListEndFavoriteDocument',
list: 'favoriteDocumentList',
});
},
});

Expand Down
3 changes: 2 additions & 1 deletion packages/apps/dms/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"Dms_Delete": "Delete",
"Dms_MyFavoriteDocuments": "My favorite documents",
"Dms_SliceAction_SearchDocument": "search document",
"Dms_SliceAction_SearchDirectory": "search directory"
"Dms_SliceAction_SearchDirectory": "search directory",
"Dms_SliceAction_SearchFavoriteDocument": "search favorite document"
}
3 changes: 2 additions & 1 deletion packages/apps/dms/src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"Dms_Delete": "Supprimer",
"Dms_MyFavoriteDocuments": "Mes fichiers favoris",
"Dms_SliceAction_SearchDocument": "recherche sur les documents",
"Dms_SliceAction_SearchDirectory": "recherche sur les dossiers"
"Dms_SliceAction_SearchDirectory": "recherche sur les dossiers",
"Dms_SliceAction_SearchFavoriteDocument": "recherche sur les documents favoris"
}
55 changes: 52 additions & 3 deletions packages/apps/dms/src/screens/MyFavoriteDocumentsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,62 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import React from 'react';
import {Screen, Text} from '@axelor/aos-mobile-ui';
import React, {useMemo, useState} from 'react';
import {
useSelector,
SearchListView,
useTranslator,
} from '@axelor/aos-mobile-core';
import {ChipSelect, Screen, useThemeColor} from '@axelor/aos-mobile-ui';
import {AuthorFilter, DocumentActionCard} from '../components';
import {searchFavoriteDocument} from '../features/documentSlice';
import {File} from '../types';

const MyFavoriteDocumentsScreen = ({}) => {
const I18n = useTranslator();
const Colors = useThemeColor();

const [author, setAuthor] = useState(null);
const [selectedExtensions, setSelectedExtensions] = useState([]);

const {user} = useSelector(state => state.user);
const {
loadingFavoriteDocument,
moreLoadingFavoriteDocument,
isListEndFavoriteDocument,
favoriteDocumentList,
} = useSelector(state => state.dms_document);

const sliceFunctionData = useMemo(
() => ({
authorId: author?.id,
extensions: selectedExtensions.map(_extension => _extension.key),
favoriteFileIds: user?.favouriteFileSet?.map(file => file.id),
}),
[author?.id, selectedExtensions, user?.favouriteFileSet],
);

return (
<Screen removeSpaceOnTop={true}>
<Text>MyFavoriteDocumentsScreen</Text>
<SearchListView
list={favoriteDocumentList}
loading={loadingFavoriteDocument}
moreLoading={moreLoadingFavoriteDocument}
isListEnd={isListEndFavoriteDocument}
sliceFunction={searchFavoriteDocument}
sliceFunctionData={sliceFunctionData}
displaySearchValue={item => item.fileName}
searchPlaceholder={I18n.t('Base_Search')}
headerChildren={<AuthorFilter author={author} setAuthor={setAuthor} />}
chipComponent={
<ChipSelect
mode="multi"
selectionItems={File.getFileExtensionList(Colors)}
onChangeValue={setSelectedExtensions}
/>
}
renderListItem={({item}) => <DocumentActionCard document={item} />}
/>
</Screen>
);
};
Expand Down
Loading