Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / drive-store / components / FileBrowser / ListView / Cells / LocationCell.tsx
blob8d71f6bd5739410e3c79ad7db07b1dcc39ed0783
1 import { useEffect, useRef, useState } from 'react';
3 import { Icon } from '@proton/components';
5 import { useLinkPath } from '../../../../store';
7 interface Props {
8     shareId: string;
9     parentLinkId: string;
10     isTrashed?: boolean;
13 export const LocationCell = ({ shareId, parentLinkId, isTrashed }: Props) => {
14     const [location, setLocation] = useState<string>();
15     const { getPath } = useLinkPath();
17     const abortController = useRef(new AbortController());
18     const previousParentLinkId = useRef(parentLinkId);
20     useEffect(() => {
21         void getPath(abortController.current.signal, shareId, parentLinkId).then(setLocation);
23         return () => {
24             // Abort only when parent ID changes which means the whole location
25             // changed and is not needed anymore. All other cases we just want
26             // to update location based on the latest cache state.
27             if (previousParentLinkId.current !== parentLinkId) {
28                 abortController.current.abort();
29                 abortController.current = new AbortController();
30                 previousParentLinkId.current = parentLinkId;
31             }
32         };
33     }, [getPath, shareId, parentLinkId]);
35     return (
36         <div key="location" title={location} className="text-ellipsis">
37             <span className="text-pre">
38                 {isTrashed && <Icon name="trash" className="mr-1" />}
39                 {location}
40             </span>
41         </div>
42     );