2023-07-04 05:26:00 +09:00
|
|
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
2023-07-04 12:47:41 -07:00
|
|
|
import { useGetConversationsQuery, useSearchQuery } from '@librechat/data-provider';
|
2023-07-04 05:26:00 +09:00
|
|
|
import { useRecoilValue, useSetRecoilState } from 'recoil';
|
|
|
|
|
|
|
|
|
|
import Conversations from '../Conversations';
|
|
|
|
|
import NavLinks from './NavLinks';
|
2023-02-06 13:27:28 -05:00
|
|
|
import NewChat from './NewChat';
|
2023-07-04 05:26:00 +09:00
|
|
|
import Pages from '../Conversations/Pages';
|
2023-07-15 10:43:15 -04:00
|
|
|
import { Panel, Spinner } from '~/components';
|
2023-07-04 05:26:00 +09:00
|
|
|
import { cn } from '~/utils/';
|
2023-03-28 20:36:21 +08:00
|
|
|
import store from '~/store';
|
feat: Auth and User System (#205)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* fix: issue with api error watcher (#12)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Update README.md
* Update LOCAL_INSTALL structure
* Add local testing instructions
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Fixup: LOCAL_INSTALL.md PS instructions (#200) (#30)
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
* feat: send user with completion to protect against abuse (#31)
* Fixup: LOCAL_INSTALL.md PS instructions (#200)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Send user id to openai to protect against abuse
* add meilisearch to gitignore
* Remove webpack
---------
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
---------
Co-authored-by: Danny Avila <110412045+danny-avila@users.noreply.github.com>
Co-authored-by: Alfredo Fomitchenko <alfredo.fomitchenko@mail.polimi.it>
2023-05-07 10:04:51 -07:00
|
|
|
import { useAuthContext } from '~/hooks/AuthContext';
|
2023-07-04 05:26:00 +09:00
|
|
|
import useDebounce from '~/hooks/useDebounce';
|
2023-05-19 20:21:34 +05:30
|
|
|
|
2023-03-12 00:32:03 +08:00
|
|
|
export default function Nav({ navVisible, setNavVisible }) {
|
2023-02-14 16:15:45 -05:00
|
|
|
const [isHovering, setIsHovering] = useState(false);
|
feat: Auth and User System (#205)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* fix: issue with api error watcher (#12)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Update README.md
* Update LOCAL_INSTALL structure
* Add local testing instructions
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Fixup: LOCAL_INSTALL.md PS instructions (#200) (#30)
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
* feat: send user with completion to protect against abuse (#31)
* Fixup: LOCAL_INSTALL.md PS instructions (#200)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Send user id to openai to protect against abuse
* add meilisearch to gitignore
* Remove webpack
---------
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
---------
Co-authored-by: Danny Avila <110412045+danny-avila@users.noreply.github.com>
Co-authored-by: Alfredo Fomitchenko <alfredo.fomitchenko@mail.polimi.it>
2023-05-07 10:04:51 -07:00
|
|
|
const { isAuthenticated } = useAuthContext();
|
2023-03-28 20:36:21 +08:00
|
|
|
const containerRef = useRef(null);
|
|
|
|
|
const scrollPositionRef = useRef(null);
|
|
|
|
|
|
|
|
|
|
const [conversations, setConversations] = useState([]);
|
|
|
|
|
// current page
|
|
|
|
|
const [pageNumber, setPageNumber] = useState(1);
|
|
|
|
|
// total pages
|
2023-03-18 14:28:10 -04:00
|
|
|
const [pages, setPages] = useState(1);
|
2023-05-18 11:09:31 -07:00
|
|
|
|
|
|
|
|
// data provider
|
feat: Auth and User System (#205)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* fix: issue with api error watcher (#12)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Update README.md
* Update LOCAL_INSTALL structure
* Add local testing instructions
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Fixup: LOCAL_INSTALL.md PS instructions (#200) (#30)
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
* feat: send user with completion to protect against abuse (#31)
* Fixup: LOCAL_INSTALL.md PS instructions (#200)
* server-side JWT auth implementation
* move oauth routes and strategies, fix bugs
* backend modifications for wiring up the frontend login and reg forms
* Add frontend data services for login and registration
* Add login and registration forms
* Implment auth context, functional client side auth
* protect routes with jwt auth
* finish local strategy (using local storage)
* Start setting up google auth
* disable token refresh, remove old auth middleware
* refactor client, add ApiErrorBoundary context
* disable google and facebook strategies
* fix: fix presets not displaying specific to user
* fix: fix issue with browser refresh
* fix: casing issue with User.js (#11)
* delete user.js to be renamed
* fix: fix casing issue with User.js
* comment out api error watcher temporarily
* feat: add google auth social login
* fix: make google login url dynamic based on dev/prod
* fix: bug where UI is briefly displayed before redirecting to login
* fix: fix cookie expires value for local auth
* Only load google strategy if client id and secret are provided
* Update .env.example files with new params
* fix issue with not redirecting to register form
* only show google login button if value is set in .env
* cleanup log messages
* Add label to button for google login on login form
* doc: fix client/server url values in .env.example
* feat: add error message details to registration failure
* Restore preventing paste on confirm password
* auto-login user after registering
* feat: forgot password (#24)
* make login/reg pages look like openai's
* add password reset data services
* new form designs similar to openai, add password reset pages
* add api's for password reset
* email utils for password reset
* remove bcrypt salt rounds from process.env
* refactor: restructure api auth code, consolidate routes (#25)
* add api's for password reset
* remove bcrypt salt rounds from process.env
* refactor: consolidate auth routes, use controller pattern
* refactor: code cleanup
* feat: migrate data to first user (#26)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes after refactor (#27)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: issue with auto-login when logging out then logging in with new browser window (#28)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: Update README and .env.example files with user system information (#29)
* refactor: use /api for auth routes
* fix: use user id instead of username
* feat: migrate data to first user on register
* fix: fix social login routes
* fix: fix issue with auto-login in new tab
* doc: update README and .env.example files
* Send user id to openai to protect against abuse
* add meilisearch to gitignore
* Remove webpack
---------
Co-authored-by: alfredo-f <alfredo.fomitchenko@mail.polimi.it>
---------
Co-authored-by: Danny Avila <110412045+danny-avila@users.noreply.github.com>
Co-authored-by: Alfredo Fomitchenko <alfredo.fomitchenko@mail.polimi.it>
2023-05-07 10:04:51 -07:00
|
|
|
const getConversationsQuery = useGetConversationsQuery(pageNumber, { enabled: isAuthenticated });
|
2023-03-28 20:36:21 +08:00
|
|
|
|
|
|
|
|
// search
|
|
|
|
|
const searchQuery = useRecoilValue(store.searchQuery);
|
|
|
|
|
const isSearchEnabled = useRecoilValue(store.isSearchEnabled);
|
|
|
|
|
const isSearching = useRecoilValue(store.isSearching);
|
2023-03-29 00:08:02 +08:00
|
|
|
const { newConversation, searchPlaceholderConversation } = store.useConversation();
|
2023-03-28 20:36:21 +08:00
|
|
|
|
|
|
|
|
// current conversation
|
|
|
|
|
const conversation = useRecoilValue(store.conversation);
|
|
|
|
|
const { conversationId } = conversation || {};
|
2023-03-29 00:08:02 +08:00
|
|
|
const setSearchResultMessages = useSetRecoilState(store.searchResultMessages);
|
2023-04-03 14:57:30 -07:00
|
|
|
const refreshConversationsHint = useRecoilValue(store.refreshConversationsHint);
|
2023-03-28 20:36:21 +08:00
|
|
|
const { refreshConversations } = store.useConversations();
|
|
|
|
|
|
|
|
|
|
const [isFetching, setIsFetching] = useState(false);
|
|
|
|
|
|
2023-04-07 10:16:53 -07:00
|
|
|
const debouncedSearchTerm = useDebounce(searchQuery, 750);
|
2023-05-18 11:09:31 -07:00
|
|
|
const searchQueryFn = useSearchQuery(debouncedSearchTerm, pageNumber, {
|
|
|
|
|
enabled:
|
2023-07-14 09:36:49 -04:00
|
|
|
!!debouncedSearchTerm && debouncedSearchTerm.length > 0 && isSearchEnabled && isSearching,
|
2023-04-07 10:16:53 -07:00
|
|
|
});
|
|
|
|
|
|
2023-03-18 14:28:10 -04:00
|
|
|
const onSearchSuccess = (data, expectedPage) => {
|
|
|
|
|
const res = data;
|
2023-03-28 20:36:21 +08:00
|
|
|
setConversations(res.conversations);
|
2023-03-18 14:28:10 -04:00
|
|
|
if (expectedPage) {
|
2023-03-28 20:36:21 +08:00
|
|
|
setPageNumber(expectedPage);
|
2023-03-14 20:21:41 -04:00
|
|
|
}
|
2023-03-18 14:28:10 -04:00
|
|
|
setPages(res.pages);
|
2023-03-18 15:59:59 -04:00
|
|
|
setIsFetching(false);
|
2023-03-29 00:08:02 +08:00
|
|
|
searchPlaceholderConversation();
|
|
|
|
|
setSearchResultMessages(res.messages);
|
2023-03-06 08:58:52 -05:00
|
|
|
};
|
|
|
|
|
|
2023-04-06 05:47:37 -07:00
|
|
|
useEffect(() => {
|
2023-04-06 08:02:08 -07:00
|
|
|
//we use isInitialLoading here instead of isLoading because query is disabled by default
|
2023-04-06 05:47:37 -07:00
|
|
|
if (searchQueryFn.isInitialLoading) {
|
|
|
|
|
setIsFetching(true);
|
2023-05-18 11:09:31 -07:00
|
|
|
} else if (searchQueryFn.data) {
|
2023-04-06 05:47:37 -07:00
|
|
|
onSearchSuccess(searchQueryFn.data);
|
|
|
|
|
}
|
2023-05-18 11:09:31 -07:00
|
|
|
}, [searchQueryFn.data, searchQueryFn.isInitialLoading]);
|
2023-03-18 15:59:59 -04:00
|
|
|
|
2023-03-18 14:28:10 -04:00
|
|
|
const clearSearch = () => {
|
2023-03-28 20:36:21 +08:00
|
|
|
setPageNumber(1);
|
|
|
|
|
refreshConversations();
|
|
|
|
|
if (conversationId == 'search') {
|
|
|
|
|
newConversation();
|
2023-03-22 16:06:11 -04:00
|
|
|
}
|
2023-03-18 14:28:10 -04:00
|
|
|
};
|
|
|
|
|
|
2023-06-11 14:46:21 -04:00
|
|
|
const moveToTop = useCallback(() => {
|
2023-05-19 20:21:34 +05:30
|
|
|
const container = containerRef.current;
|
|
|
|
|
if (container) {
|
|
|
|
|
scrollPositionRef.current = container.scrollTop;
|
|
|
|
|
}
|
2023-06-11 14:46:21 -04:00
|
|
|
}, [containerRef, scrollPositionRef]);
|
2023-05-19 20:21:34 +05:30
|
|
|
|
2023-03-15 04:05:14 +08:00
|
|
|
const nextPage = async () => {
|
2023-03-14 20:21:41 -04:00
|
|
|
moveToTop();
|
2023-04-07 10:16:53 -07:00
|
|
|
setPageNumber(pageNumber + 1);
|
2023-03-15 04:05:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const previousPage = async () => {
|
2023-03-14 20:21:41 -04:00
|
|
|
moveToTop();
|
2023-04-07 10:16:53 -07:00
|
|
|
setPageNumber(pageNumber - 1);
|
2023-03-05 14:41:50 -05:00
|
|
|
};
|
2023-02-14 16:15:45 -05:00
|
|
|
|
2023-03-14 20:21:41 -04:00
|
|
|
useEffect(() => {
|
2023-04-02 12:49:12 -07:00
|
|
|
if (getConversationsQuery.data) {
|
|
|
|
|
if (isSearching) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let { conversations, pages } = getConversationsQuery.data;
|
|
|
|
|
if (pageNumber > pages) {
|
|
|
|
|
setPageNumber(pages);
|
|
|
|
|
} else {
|
|
|
|
|
if (!isSearching) {
|
2023-05-18 11:09:31 -07:00
|
|
|
conversations = conversations.sort(
|
2023-07-14 09:36:49 -04:00
|
|
|
(a, b) => new Date(b.createdAt) - new Date(a.createdAt),
|
2023-05-18 11:09:31 -07:00
|
|
|
);
|
2023-04-02 12:49:12 -07:00
|
|
|
}
|
|
|
|
|
setConversations(conversations);
|
|
|
|
|
setPages(pages);
|
|
|
|
|
}
|
2023-03-18 14:28:10 -04:00
|
|
|
}
|
2023-04-02 12:49:12 -07:00
|
|
|
}, [getConversationsQuery.isSuccess, getConversationsQuery.data, isSearching, pageNumber]);
|
2023-02-13 23:14:35 -05:00
|
|
|
|
2023-04-03 14:57:30 -07:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (!isSearching) {
|
|
|
|
|
getConversationsQuery.refetch();
|
|
|
|
|
}
|
2023-07-15 10:43:15 -04:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2023-04-03 14:57:30 -07:00
|
|
|
}, [pageNumber, conversationId, refreshConversationsHint]);
|
|
|
|
|
|
2023-03-28 20:36:21 +08:00
|
|
|
const toggleNavVisible = () => {
|
2023-05-18 11:44:07 -07:00
|
|
|
setNavVisible((prev) => !prev);
|
2023-03-28 20:36:21 +08:00
|
|
|
};
|
|
|
|
|
|
2023-03-07 13:53:23 -05:00
|
|
|
const containerClasses =
|
2023-04-02 12:49:12 -07:00
|
|
|
getConversationsQuery.isLoading && pageNumber === 1
|
2023-03-07 13:53:23 -05:00
|
|
|
? 'flex flex-col gap-2 text-gray-100 text-sm h-full justify-center items-center'
|
|
|
|
|
: 'flex flex-col gap-2 text-gray-100 text-sm';
|
2023-02-25 10:16:21 -05:00
|
|
|
|
2023-02-06 13:27:28 -05:00
|
|
|
return (
|
2023-03-12 00:32:03 +08:00
|
|
|
<>
|
2023-07-15 17:56:18 +05:30
|
|
|
<div
|
2023-07-15 10:43:15 -04:00
|
|
|
className="nav active dark flex-shrink-0 overflow-x-hidden bg-gray-900 transition-all duration-200 ease-in-out"
|
|
|
|
|
style={{
|
|
|
|
|
width: navVisible ? '260px' : '0px',
|
|
|
|
|
visibility: navVisible ? 'visible' : 'hidden',
|
|
|
|
|
}}
|
2023-07-15 17:56:18 +05:30
|
|
|
>
|
2023-07-15 10:43:15 -04:00
|
|
|
<div className="h-full w-[260px]">
|
|
|
|
|
<div className="flex h-full min-h-0 flex-col ">
|
|
|
|
|
<div className="scrollbar-trigger relative flex h-full w-full flex-1 items-start border-white/20">
|
|
|
|
|
<nav className="relative flex h-full flex-1 flex-col space-y-1 p-2">
|
|
|
|
|
<div className="mb-2 flex h-11 flex-row">
|
|
|
|
|
<NewChat />
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
className={cn(
|
|
|
|
|
'nav-close-button inline-flex h-11 w-11 items-center justify-center rounded-md border border-white/20 text-white hover:bg-gray-500/10',
|
|
|
|
|
)}
|
|
|
|
|
onClick={toggleNavVisible}
|
|
|
|
|
>
|
|
|
|
|
<span className="sr-only">Close sidebar</span>
|
|
|
|
|
<Panel open={false} />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
className={`flex-1 flex-col overflow-y-auto ${
|
|
|
|
|
isHovering ? '' : 'scrollbar-transparent'
|
|
|
|
|
} border-b border-white/20`}
|
|
|
|
|
onMouseEnter={() => setIsHovering(true)}
|
|
|
|
|
onMouseLeave={() => setIsHovering(false)}
|
|
|
|
|
ref={containerRef}
|
2023-07-04 05:26:00 +09:00
|
|
|
>
|
2023-07-15 10:43:15 -04:00
|
|
|
<div className={containerClasses}>
|
|
|
|
|
{(getConversationsQuery.isLoading && pageNumber === 1) || isFetching ? (
|
|
|
|
|
<Spinner />
|
|
|
|
|
) : (
|
|
|
|
|
<Conversations
|
|
|
|
|
conversations={conversations}
|
|
|
|
|
conversationId={conversationId}
|
|
|
|
|
moveToTop={moveToTop}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
<Pages
|
|
|
|
|
pageNumber={pageNumber}
|
|
|
|
|
pages={pages}
|
|
|
|
|
nextPage={nextPage}
|
|
|
|
|
previousPage={previousPage}
|
2023-03-12 00:32:03 +08:00
|
|
|
/>
|
2023-07-15 10:43:15 -04:00
|
|
|
</div>
|
2023-03-12 00:32:03 +08:00
|
|
|
</div>
|
2023-07-15 10:43:15 -04:00
|
|
|
<NavLinks clearSearch={clearSearch} isSearchEnabled={isSearchEnabled} />
|
|
|
|
|
</nav>
|
|
|
|
|
</div>
|
2023-03-12 00:32:03 +08:00
|
|
|
</div>
|
2023-02-06 13:27:28 -05:00
|
|
|
</div>
|
2023-03-12 00:32:03 +08:00
|
|
|
</div>
|
2023-05-19 20:21:34 +05:30
|
|
|
{!navVisible && (
|
2023-07-15 10:43:15 -04:00
|
|
|
<div className="absolute left-2 top-2 z-10 hidden md:inline-block">
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
className="nav-open-button flex h-11 cursor-pointer items-center gap-3 rounded-md border border-black/10 bg-white p-3 text-sm text-black transition-colors duration-200 hover:bg-gray-50 dark:border-white/20 dark:bg-gray-800 dark:hover:bg-gray-700"
|
|
|
|
|
onClick={toggleNavVisible}
|
|
|
|
|
>
|
|
|
|
|
<div className="flex items-center justify-center">
|
|
|
|
|
<span className="sr-only">Open sidebar</span>
|
|
|
|
|
<Panel open={true} />
|
|
|
|
|
</div>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2023-05-19 20:21:34 +05:30
|
|
|
)}
|
|
|
|
|
|
2023-05-18 11:09:31 -07:00
|
|
|
<div className={'nav-mask' + (navVisible ? ' active' : '')} onClick={toggleNavVisible}></div>
|
2023-03-12 00:32:03 +08:00
|
|
|
</>
|
2023-02-06 13:27:28 -05:00
|
|
|
);
|
|
|
|
|
}
|