diff --git a/application/api/user/routes.py b/application/api/user/routes.py
index c33a6c84c..8e62683e6 100644
--- a/application/api/user/routes.py
+++ b/application/api/user/routes.py
@@ -433,6 +433,8 @@ class CombinedJson(Resource):
@api.doc(description="Provide JSON file with combined available indexes")
def get(self):
user = "local"
+ sort_field = request.args.get('sort', 'date') # Default to 'date'
+ sort_order = request.args.get('order', "desc") # Default to 'desc'
data = [
{
"name": "default",
@@ -445,7 +447,7 @@ def get(self):
]
try:
- for index in sources_collection.find({"user": user}).sort("date", -1):
+ for index in sources_collection.find({"user": user}).sort(sort_field, 1 if sort_order=="asc" else -1):
data.append(
{
"id": str(index["_id"]),
diff --git a/frontend/src/Navigation.tsx b/frontend/src/Navigation.tsx
index ce23e90ef..3591469b1 100644
--- a/frontend/src/Navigation.tsx
+++ b/frontend/src/Navigation.tsx
@@ -254,7 +254,7 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) {
ref={navRef}
className={`${
!navOpen && '-ml-96 md:-ml-[18rem]'
- } duration-20 fixed top-0 z-40 flex h-full w-72 flex-col border-r-[1px] border-b-0 bg-white transition-all dark:border-r-purple-taupe dark:bg-chinese-black dark:text-white`}
+ } duration-20 fixed top-0 z-20 flex h-full w-72 flex-col border-r-[1px] border-b-0 bg-white transition-all dark:border-r-purple-taupe dark:bg-chinese-black dark:text-white`}
>
=> apiClient.get(endpoints.USER.DOCS),
+ getDocs: (sort = 'date', order = 'desc'): Promise
=>
+ apiClient.get(`${endpoints.USER.DOCS}?sort=${sort}&order=${order}`),
checkDocs: (data: any): Promise =>
apiClient.post(endpoints.USER.DOCS_CHECK, data),
getAPIKeys: (): Promise => apiClient.get(endpoints.USER.API_KEYS),
diff --git a/frontend/src/conversation/ConversationBubble.tsx b/frontend/src/conversation/ConversationBubble.tsx
index a9a05168b..284c2b568 100644
--- a/frontend/src/conversation/ConversationBubble.tsx
+++ b/frontend/src/conversation/ConversationBubble.tsx
@@ -474,7 +474,7 @@ function AllSources(sources: AllSourcesProps) {
>
) : null}
-
+
{source.text}
diff --git a/frontend/src/preferences/preferenceApi.ts b/frontend/src/preferences/preferenceApi.ts
index ed730f7c6..af1060b83 100644
--- a/frontend/src/preferences/preferenceApi.ts
+++ b/frontend/src/preferences/preferenceApi.ts
@@ -3,9 +3,12 @@ import userService from '../api/services/userService';
import { Doc } from '../models/misc';
//Fetches all JSON objects from the source. We only use the objects with the "model" property in SelectDocsModal.tsx. Hopefully can clean up the source file later.
-export async function getDocs(): Promise {
+export async function getDocs(
+ sort = 'date',
+ order = 'desc',
+): Promise {
try {
- const response = await userService.getDocs();
+ const response = await userService.getDocs(sort, order);
const data = await response.json();
const docs: Doc[] = [];
diff --git a/frontend/src/settings/Documents.tsx b/frontend/src/settings/Documents.tsx
index 004b6f487..f94d1a87b 100644
--- a/frontend/src/settings/Documents.tsx
+++ b/frontend/src/settings/Documents.tsx
@@ -45,14 +45,30 @@ const Documents: React.FC = ({
const [modalState, setModalState] = useState('INACTIVE'); // Initialize with inactive state
const [isOnboarding, setIsOnboarding] = useState(false); // State for onboarding flag
const [loading, setLoading] = useState(false);
-
+ const [sortField, setSortField] = useState<'date' | 'tokens'>('date');
+ const [sortOrder, setSortOrder] = useState<'asc' | 'desc'>('desc');
const syncOptions = [
{ label: 'Never', value: 'never' },
{ label: 'Daily', value: 'daily' },
{ label: 'Weekly', value: 'weekly' },
{ label: 'Monthly', value: 'monthly' },
];
-
+ const refreshDocs = (field: 'date' | 'tokens') => {
+ if (field === sortField) {
+ setSortOrder(sortOrder === 'asc' ? 'desc' : 'asc');
+ } else {
+ setSortOrder('desc');
+ setSortField(field);
+ }
+ getDocs(sortField, sortOrder)
+ .then((data) => {
+ dispatch(setSourceDocs(data));
+ })
+ .catch((error) => console.error(error))
+ .finally(() => {
+ setLoading(false);
+ });
+ };
const handleManageSync = (doc: Doc, sync_frequency: string) => {
setLoading(true);
userService
@@ -110,19 +126,28 @@ const Documents: React.FC = ({
{t('settings.documents.date')}
-
+ refreshDocs('date')}
+ src={caretSort}
+ alt="sort"
+ />
|
{t('settings.documents.tokenUsage')}
-
+ refreshDocs('tokens')}
+ src={caretSort}
+ alt="sort"
+ />
|
{t('settings.documents.type')}
-
|
|