Skip to content

Commit

Permalink
Cleanup home webview
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfheij-sil committed Nov 28, 2024
1 parent bb091b7 commit cb4c4b2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
"%getResources_type_XR%": "XML Resource",
"%getResources_type_unknown%": "Unknown resource type",
"%getResources_update%": "Update",
"%home_dialog_title%": "Home",
"%home_name%": "Name",
"%mainMenu_openGetResources%": "Get Resources...",
"%mainMenu_openHome%": "Open Home Dialog..."
"%mainMenu_openGetResources%": "Get Resources"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
"metadata": {},
"localizedStrings": {
"en": {
"%home_dialog_title%": "Home",
"%home_action%": "Action",
"%home_getResources%": "Get Resources",
"%home_language%": "Language",
"%home_loadingProjectsAndResources%": "Loading Projects and Resources",
"%home_dialogTitle%": "Home",
"%home_name%": "Name",
"%mainMenu_openHome%": "Open Home Dialog..."
"%mainMenu_openHome%": "Home..."
}
}
}
164 changes: 21 additions & 143 deletions extensions/src/platform-home/src/home.web-view.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import papi from '@papi/frontend';
import { useLocalizedStrings } from '@papi/frontend/react';
import { BookOpen, Home, Plus } from 'lucide-react';
import {
Expand All @@ -7,11 +6,6 @@ import {
CardContent,
CardHeader,
CardTitle,
// DropdownMenu,
// DropdownMenuContent,
// DropdownMenuItem,
// DropdownMenuSeparator,
// DropdownMenuTrigger,
Label,
LocalizeKey,
Spinner,
Expand All @@ -21,105 +15,30 @@ import {
TableHead,
TableHeader,
TableRow,
usePromise,
} from 'platform-bible-react';
import { getErrorMessage } from 'platform-bible-utils';
import { useCallback } from 'react';

const LOCALIZED_STRING_KEYS: LocalizeKey[] = [
'%downloadResources_action%',
'%downloadResources_dialog_subtitle%',
'%downloadResources_dialog_title%',
'%downloadResources_filterInput%',
'%downloadResources_fullName%',
'%downloadResources_get%',
'%downloadResources_installed%',
'%downloadResources_language%',
'%downloadResources_languageFilter%',
'%downloadResources_loadingResources%',
'%downloadResources_noResults%',
'%downloadResources_open%',
'%downloadResources_remove%',
'%downloadResources_size%',
'%downloadResources_type%',
'%downloadResources_typeFilter%',
'%downloadResources_type_DBL%',
'%downloadResources_type_ER%',
'%downloadResources_type_SLR%',
'%downloadResources_type_XR%',
'%downloadResources_type_unknown%',
'%downloadResources_update%',
'%home_dialog_title%',
'%home_action%',
'%home_dialogTitle%',
'%home_getResources%',
'%home_language%',
'%home_loadingProjectsAndResources%',
'%home_name%',
];

// const getActionButtonContent = (
// resource: DblResourceData,
// buttonText: string,
// installResource: (dblEntryUid: string, action: 'install' | 'remove') => void,
// ) => {
// return (
// <Button variant="outline" onClick={() => installResource(resource.dblEntryUid, 'install')}>
// {buttonText}
// </Button>
// );
// };

// const getActionContent = (
// resource: DblResourceData,
// idsBeingHandled: string[],
// getText: string,
// updateText: string,
// installedText: string,
// installResource: (dblEntryUid: string, action: 'install' | 'remove') => void,
// ) => {
// const isBeingHandled = idsBeingHandled.includes(resource.dblEntryUid);
// if (isBeingHandled) {
// return (
// <Button variant="outline">
// <Spinner className="tw-h-5 tw-py-[1px]" />
// </Button>
// );
// }
// if (!resource.installed) {
// return getActionButtonContent(resource, getText, installResource);
// }
// if (resource.updateAvailable) {
// return getActionButtonContent(resource, updateText, installResource);
// }
// return <Label className="tw-h-6 tw-my-2 tw-flex tw-items-center">{installedText}</Label>;
// };

globalThis.webViewComponent = function DownloadResourcesDialog() {
const [localizedStrings] = useLocalizedStrings(LOCALIZED_STRING_KEYS);

const actionText: string = localizedStrings['%downloadResources_action%'];
const getResourcesText: string = localizedStrings['%downloadResources_dialog_title%'];
// const getText: string = localizedStrings['%downloadResources_get%'];
// const installedText: string = localizedStrings['%downloadResources_installed%'];
const languageText: string = localizedStrings['%downloadResources_language%'];
const loadingResourcesText: string = localizedStrings['%downloadResources_loadingResources%'];
// const openText: string = localizedStrings['%downloadResources_open%'];
// const removeText: string = localizedStrings['%downloadResources_remove%'];
// const updateText: string = localizedStrings['%downloadResources_update%'];
const dialogTitleText: string = localizedStrings['%home_dialog_title%'];
const actionText: string = localizedStrings['%home_action%'];
const dialogTitleText: string = localizedStrings['%home_dialogTitle%'];
const getResourcesText: string = localizedStrings['%home_getResources%'];
const languageText: string = localizedStrings['%home_language%'];
const loadingProjectsAndResourcesText: string =
localizedStrings['%home_loadingProjectsAndResources%'];
const nameText: string = localizedStrings['%home_name%'];

const [sharedProjectsInfo, isLoadingSharedProjectsInfo] = usePromise(
useCallback(async () => {
// Gather S/R-able projects
try {
const projectsInfo = await papi.commands.sendCommand(
'paratextBibleSendReceive.getSharedProjects',
);
return projectsInfo;
} catch (e) {
console.log(getErrorMessage(e));
return undefined;
}
}, []),
undefined,
);
const projects: unknown[] = [];
const isLoading: boolean = false;

return (
<Card className="tw-border-0 tw-rounded-none">
Expand All @@ -132,9 +51,9 @@ globalThis.webViewComponent = function DownloadResourcesDialog() {
</div>
</CardHeader>
<CardContent>
{isLoadingSharedProjectsInfo || !sharedProjectsInfo ? (
{isLoading ? (
<div className="tw-flex tw-flex-col tw-items-center tw-gap-2">
<Label>{loadingResourcesText}</Label>
<Label>{loadingProjectsAndResourcesText}</Label>
<Spinner />
</div>
) : (
Expand All @@ -155,56 +74,15 @@ globalThis.webViewComponent = function DownloadResourcesDialog() {
</TableRow>
</TableHeader>
<TableBody>
{Object.values(sharedProjectsInfo).map((resource) => (
<TableRow key={resource.id}>
{projects.map(() => (
<TableRow>
<TableCell>
<BookOpen className="tw-pr-0" size={18} />
</TableCell>
<TableCell>{resource.fullName}</TableCell>
<TableCell className="tw-font-medium">{resource.fullName}</TableCell>
<TableCell>{resource.language}</TableCell>
<TableCell>
{/* <div className="tw-flex tw-justify-between">
{getActionContent(
resource,
installInfo.map((info) => info.dblEntryUid),
getText,
updateText,
installedText,
installOrRemoveResource,
)}
{resource.installed && (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost">
<Ellipsis className="tw-w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
<DropdownMenuItem
onClick={() =>
papi.commands.sendCommand(
'platformScriptureEditor.openResourceViewer',
resource.projectId,
)
}
>
<span>{openText}</span>
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={() =>
installOrRemoveResource(resource.dblEntryUid, 'remove')
}
>
<span>{removeText}</span>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)}
</div> */}
</TableCell>
<TableCell>A</TableCell>
<TableCell className="tw-font-medium">B</TableCell>
<TableCell>C</TableCell>
<TableCell>D </TableCell>
</TableRow>
))}
</TableBody>
Expand Down

0 comments on commit cb4c4b2

Please sign in to comment.