Add support for loading files from Google Drive

#vibecoded
This commit is contained in:
Przemek Więch
2026-05-19 00:38:16 +02:00
parent 60e076fca1
commit 55a1626cf4
26 changed files with 2005 additions and 107 deletions

View File

@@ -0,0 +1,59 @@
import queryString from 'query-string';
import {FormattedMessage} from 'react-intl';
import {useNavigate} from 'react-router';
import {Icon} from 'semantic-ui-react';
import {
googleDriveService,
isGoogleDriveConfigured,
} from '../datasource/google_drive_service';
import {MenuItem, MenuType} from './menu_item';
interface Props {
menuType: MenuType;
onTokenAcquired?: () => void;
}
/**
* Component representing the Google Drive menu option.
* It handles authenticating the user and launching the Google Picker to select files.
*/
export function GoogleDriveMenu(props: Props) {
const navigate = useNavigate();
// Do not render the menu item if Google Drive API credentials are not configured.
if (!isGoogleDriveConfigured()) {
return null;
}
async function handleClick() {
try {
// 1. Request access token
await googleDriveService.requestToken();
if (props.onTokenAcquired) {
props.onTokenAcquired();
}
// 2. Open Google Picker
await googleDriveService.showPicker((fileId) => {
navigate({
pathname: '/view',
search: queryString.stringify({
source: 'google-drive',
fileId,
}),
});
});
} catch (err) {
console.error('Failed Google Drive login/file picking:', err);
}
}
return (
<MenuItem onClick={handleClick} menuType={props.menuType}>
<Icon name="google drive" />
<FormattedMessage
id="menu.load_from_google_drive"
defaultMessage="Load from Google Drive"
/>
</MenuItem>
);
}