fix: export/sharing notes on mobile webview (#1644)
This commit is contained in:
36
packages/web/src/javascripts/Utils/NoteExportUtils.ts
Normal file
36
packages/web/src/javascripts/Utils/NoteExportUtils.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { WebApplication } from '@/Application/Application'
|
||||
import { SNNote } from '@standardnotes/snjs'
|
||||
|
||||
export const getNoteFormat = (application: WebApplication, note: SNNote) => {
|
||||
const editor = application.componentManager.editorForNote(note)
|
||||
const format = editor?.package_info?.file_type || 'txt'
|
||||
return format
|
||||
}
|
||||
|
||||
export const getNoteFileName = (application: WebApplication, note: SNNote): string => {
|
||||
const format = getNoteFormat(application, note)
|
||||
return `${note.title}.${format}`
|
||||
}
|
||||
|
||||
export const getNoteBlob = (application: WebApplication, note: SNNote) => {
|
||||
const format = getNoteFormat(application, note)
|
||||
let type: string
|
||||
switch (format) {
|
||||
case 'html':
|
||||
type = 'text/html'
|
||||
break
|
||||
case 'json':
|
||||
type = 'application/json'
|
||||
break
|
||||
case 'md':
|
||||
type = 'text/markdown'
|
||||
break
|
||||
default:
|
||||
type = 'text/plain'
|
||||
break
|
||||
}
|
||||
const blob = new Blob([note.text], {
|
||||
type,
|
||||
})
|
||||
return blob
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Platform, platformFromString } from '@standardnotes/snjs'
|
||||
import { DeviceInterface, MobileDeviceInterface, Platform, platformFromString } from '@standardnotes/snjs'
|
||||
import { IsDesktopPlatform, IsWebPlatform } from '@/Constants/Version'
|
||||
import { EMAIL_REGEX } from '../Constants/Constants'
|
||||
import { MediaQueryBreakpoints } from '@/Hooks/useMediaQuery'
|
||||
@@ -31,7 +31,11 @@ export function getPlatformString() {
|
||||
}
|
||||
}
|
||||
|
||||
export function getPlatform(): Platform {
|
||||
export function getPlatform(device: DeviceInterface | MobileDeviceInterface): Platform {
|
||||
if ('platform' in device) {
|
||||
return device.platform
|
||||
}
|
||||
|
||||
return platformFromString(getPlatformString())
|
||||
}
|
||||
|
||||
@@ -204,3 +208,17 @@ export const disableIosTextFieldZoom = () => {
|
||||
}
|
||||
|
||||
export const isMobileScreen = () => !window.matchMedia(MediaQueryBreakpoints.md).matches
|
||||
|
||||
export const getBase64FromBlob = (blob: Blob) => {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
const reader = new FileReader()
|
||||
reader.onloadend = () => {
|
||||
if (reader.result) {
|
||||
resolve(reader.result.toString())
|
||||
} else {
|
||||
reject()
|
||||
}
|
||||
}
|
||||
reader.readAsDataURL(blob)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user