Skip to content

Commit

Permalink
add LAST_PROJECT_CLICKED
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadPCh committed Oct 7, 2024
1 parent 0bdc388 commit d83daf9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/components/views/projects/ProjectsIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { DefaultQFBanner } from '@/components/DefaultQFBanner';
import NotAvailable from '@/components/NotAvailable';
import { fetchProjects, IQueries } from './services';
import { IProject } from '@/apollo/types/types';
import { LAST_PROJECT_CLICKED } from './constants';

export interface IProjectsView {
projects: IProject[];
Expand Down Expand Up @@ -167,14 +168,14 @@ const ProjectsIndex = (props: IProjectsView) => {

// Save last clicked project
const handleProjectClick = (slug: string) => {
localStorage.setItem('lastProjectClicked', slug);
sessionStorage.setItem(LAST_PROJECT_CLICKED, slug);
};

// Scroll to last clicked project
useEffect(() => {
if (!isFetching && !isFetchingNextPage) {
const lastProjectClicked =
localStorage.getItem('lastProjectClicked');
sessionStorage.getItem(LAST_PROJECT_CLICKED);
if (lastProjectClicked) {
const element = document.getElementById(lastProjectClicked);
if (element) {
Expand All @@ -183,7 +184,7 @@ const ProjectsIndex = (props: IProjectsView) => {
behavior: 'smooth',
});
}
localStorage.removeItem('lastProjectClicked');
sessionStorage.removeItem(LAST_PROJECT_CLICKED);
}
}
}, [isFetching, isFetchingNextPage]);
Expand Down
1 change: 1 addition & 0 deletions src/components/views/projects/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const LAST_PROJECT_CLICKED = 'lastProjectClicked';

0 comments on commit d83daf9

Please sign in to comment.