2023-04-06 05:47:37 -07:00
|
|
|
import { useState, useEffect, useRef } from 'react';
|
2023-02-06 13:27:28 -05:00
|
|
|
import NewChat from './NewChat';
|
2023-02-14 16:15:45 -05:00
|
|
|
import Spinner from '../svg/Spinner';
|
2023-03-18 14:28:10 -04:00
|
|
|
import Pages from '../Conversations/Pages';
|
2023-02-07 10:26:19 -05:00
|
|
|
import Conversations from '../Conversations';
|
2023-02-06 13:27:28 -05:00
|
|
|
import NavLinks from './NavLinks';
|
2023-04-02 12:49:12 -07:00
|
|
|
import { useRecoilValue, useSetRecoilState } from 'recoil';
|
2023-04-06 05:47:37 -07:00
|
|
|
import { useGetConversationsQuery, useSearchQuery } from '~/data-provider';
|
|
|
|
|
import useDebounce from '~/hooks/useDebounce';
|
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-03-18 14:28:10 -04:00
|
|
|
|
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:
|
|
|
|
|
!!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-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(
|
|
|
|
|
(a, b) => new Date(b.createdAt) - new Date(a.createdAt)
|
|
|
|
|
);
|
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();
|
|
|
|
|
}
|
|
|
|
|
}, [pageNumber, conversationId, refreshConversationsHint]);
|
|
|
|
|
|
2023-03-28 20:36:21 +08:00
|
|
|
const moveToTop = () => {
|
|
|
|
|
const container = containerRef.current;
|
|
|
|
|
if (container) {
|
|
|
|
|
scrollPositionRef.current = container.scrollTop;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const toggleNavVisible = () => {
|
|
|
|
|
setNavVisible(prev => !prev);
|
|
|
|
|
};
|
|
|
|
|
|
2023-03-12 00:32:03 +08:00
|
|
|
useEffect(() => {
|
2023-03-14 20:21:41 -04:00
|
|
|
setNavVisible(false);
|
2023-04-02 12:49:12 -07:00
|
|
|
}, [conversationId, setNavVisible]);
|
2023-03-12 00:32:03 +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-03-14 20:21:41 -04:00
|
|
|
<div
|
|
|
|
|
className={
|
|
|
|
|
'nav dark bg-gray-900 md:fixed md:inset-y-0 md:flex md:w-[260px] md:flex-col' +
|
|
|
|
|
(navVisible ? ' active' : '')
|
|
|
|
|
}
|
|
|
|
|
>
|
2023-03-12 00:32:03 +08:00
|
|
|
<div className="flex h-full min-h-0 flex-col ">
|
2023-05-18 11:09:31 -07:00
|
|
|
<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">
|
2023-03-12 00:32:03 +08:00
|
|
|
<NewChat />
|
|
|
|
|
<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}
|
|
|
|
|
>
|
|
|
|
|
<div className={containerClasses}>
|
2023-04-02 12:49:12 -07:00
|
|
|
{(getConversationsQuery.isLoading && pageNumber === 1) || isFetching ? (
|
2023-03-12 00:32:03 +08:00
|
|
|
<Spinner />
|
|
|
|
|
) : (
|
|
|
|
|
<Conversations
|
2023-03-28 20:36:21 +08:00
|
|
|
conversations={conversations}
|
2023-03-12 00:32:03 +08:00
|
|
|
conversationId={conversationId}
|
2023-03-15 04:05:14 +08:00
|
|
|
moveToTop={moveToTop}
|
2023-03-12 00:32:03 +08:00
|
|
|
/>
|
|
|
|
|
)}
|
2023-03-18 14:28:10 -04:00
|
|
|
<Pages
|
|
|
|
|
pageNumber={pageNumber}
|
|
|
|
|
pages={pages}
|
|
|
|
|
nextPage={nextPage}
|
|
|
|
|
previousPage={previousPage}
|
|
|
|
|
/>
|
2023-03-12 00:32:03 +08:00
|
|
|
</div>
|
2023-02-14 16:15:45 -05:00
|
|
|
</div>
|
2023-05-18 11:09:31 -07:00
|
|
|
<NavLinks clearSearch={clearSearch} isSearchEnabled={isSearchEnabled} />
|
2023-03-12 00:32:03 +08:00
|
|
|
</nav>
|
|
|
|
|
</div>
|
2023-02-06 13:27:28 -05:00
|
|
|
</div>
|
2023-03-12 00:32:03 +08:00
|
|
|
<button
|
|
|
|
|
type="button"
|
2023-03-14 20:21:41 -04:00
|
|
|
className="nav-close-button -ml-0.5 -mt-0.5 inline-flex h-10 w-10 items-center justify-center rounded-md text-white hover:text-gray-900 hover:text-white focus:outline-none focus:ring-white"
|
2023-03-12 00:32:03 +08:00
|
|
|
onClick={toggleNavVisible}
|
|
|
|
|
>
|
|
|
|
|
<span className="sr-only">Open sidebar</span>
|
|
|
|
|
<svg
|
|
|
|
|
stroke="currentColor"
|
|
|
|
|
fill="none"
|
|
|
|
|
strokeWidth="1.5"
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
strokeLinecap="round"
|
|
|
|
|
strokeLinejoin="round"
|
|
|
|
|
className="h-6 w-6"
|
|
|
|
|
height="1em"
|
|
|
|
|
width="1em"
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
>
|
2023-05-18 11:09:31 -07:00
|
|
|
<line x1="3" y1="6" x2="15" y2="18" />
|
|
|
|
|
<line x1="3" y1="18" x2="15" y2="6" />
|
2023-03-12 00:32:03 +08:00
|
|
|
</svg>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
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
|
|
|
);
|
|
|
|
|
}
|