Skip to content

Commit

Permalink
ch: add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
khalifan-kfan committed Jun 15, 2024
1 parent 79d0f78 commit 4503237
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { IReactionPublic } from 'mobx';

export type IDownloadStatus = 'ready' | 'pending' | 'finalizing' | 'complete' | 'error';


@Injectable({ providedIn: 'root' })
export class ResourcesToolService extends PicsaAsyncService {
/** Track active downloadStatus by resource ID */
Expand Down Expand Up @@ -264,6 +263,7 @@ export class ResourcesToolService extends PicsaAsyncService {
private async shareFileNative(resource: RxDocument<schemas.IResourceFile>, url: string) {
try {
const file = await this.getFileAttachmentURI(resource);
//if file is downloaded from before
if (file) {
const res = await lastValueFrom(this.fileService.downloadFile(url, 'blob'));
if (res?.data) {
Expand All @@ -282,6 +282,7 @@ export class ResourcesToolService extends PicsaAsyncService {
matIcon: 'success',
message: 'Please wait as the file is being downloaded for sharing.',
});
//TODO: complete use case when file is not downloaded
}
} catch (error) {
this.notificationService.showUserNotification({
Expand All @@ -291,24 +292,27 @@ export class ResourcesToolService extends PicsaAsyncService {
console.error(error);
}
}


public async shareResource(resource: RxDocument<schemas.IResourceFile> | RxDocument<schemas.IResourceLink >, resourceType: string) {

public async shareResource(
resource: RxDocument<schemas.IResourceFile> | RxDocument<schemas.IResourceLink>,
resourceType: string
) {
try {
const isShareContent = await Share.canShare();
let url = resourceType === 'file' ? resource._data.url : resource.url;
if (resourceType === 'link' && resource?.subtype === 'play_store') {
url = `https://play.google.com/store/apps/details?id=${url}`;
}

if (Capacitor.isNativePlatform()) {
if (resource.type === 'file') {
await this.shareFileNative(resource as RxDocument<schemas.IResourceFile>, url);
} else {
await this.shareLink(url, isShareContent.value);
}
} else {
await this.shareLink(url, isShareContent.value);
// await this.shareLink(url, isShareContent.value);

}
} catch (error) {
console.error('Error sharing resource:', error);
Expand All @@ -318,8 +322,4 @@ export class ResourcesToolService extends PicsaAsyncService {
});
}
}




}

0 comments on commit 4503237

Please sign in to comment.