-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kévin Commaille
committed
Jan 18, 2021
1 parent
e91b01d
commit 558defe
Showing
11 changed files
with
160 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as Etebase from "etebase"; | ||
import * as IntentLauncher from "expo-intent-launcher"; | ||
import RNFS from "react-native-fs"; | ||
import { getItemData } from "./utils"; | ||
|
||
export function canExport() { | ||
return true; | ||
} | ||
|
||
export async function exportItem(item: Etebase.Item) { | ||
const { name, content } = await getItemData(item, "export"); | ||
const result = await IntentLauncher.startActivityAsync("android.intent.action.CREATE_DOCUMENT", { | ||
type: "text/markdown", | ||
category: "android.intent.category.OPENABLE", | ||
extra: { "android.intent.extra.TITLE": `${name}.md` }, | ||
}); | ||
if (result.resultCode === IntentLauncher.ResultCode.Success && result?.data) { | ||
await RNFS.writeFile(result.data, content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as Etebase from "etebase"; | ||
import { Share } from "react-native"; | ||
import { getItemData } from "./utils"; | ||
|
||
export function canExport() { | ||
return true; | ||
} | ||
|
||
export async function exportItem(item: Etebase.Item) { | ||
const { name, content } = await getItemData(item, "export"); | ||
|
||
await Share.share({ | ||
message: content, | ||
title: name, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import * as Etebase from "etebase"; | ||
|
||
export function canExport() { | ||
return false; | ||
} | ||
|
||
export async function exportItem(item: Etebase.Item) { | ||
const { name } = item.getMeta(); | ||
throw Error(`Cannot export item "${name}". Exporting is not implemented on this Platform`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as Etebase from "etebase"; | ||
import FileSaver from "file-saver"; | ||
import { getItemData } from "./utils"; | ||
|
||
export function canExport() { | ||
try { | ||
const canBlob = !!new Blob; | ||
return canBlob; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
export async function exportItem(item: Etebase.Item) { | ||
const { name, content } = await getItemData(item, "export"); | ||
const blob = new Blob([content], { type: "text/markdown;charset=utf-8" }); | ||
FileSaver.saveAs(blob, `${name}.md`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./export"; | ||
export * from "./share"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
import * as Etebase from "etebase"; | ||
import YAML from "js-yaml"; | ||
|
||
export async function getItemData(item: Etebase.Item) { | ||
const { name } = item.getMeta(); | ||
const content = await item.getContent(Etebase.OutputFormat.String); | ||
return { | ||
name, | ||
content, | ||
export async function getItemData(item: Etebase.Item, format = "") { | ||
const data = { | ||
name: item.getMeta().name, | ||
content: "", | ||
}; | ||
const content = await item.getContent(Etebase.OutputFormat.String); | ||
|
||
switch (format) { | ||
case "export": { | ||
const frontmatter = YAML.dump({ title: data.name }); | ||
data.content = `---\n${frontmatter}---\n\n${content}`; | ||
break; | ||
} | ||
default: { | ||
data.content = `# ${data.name}\n\n${content}`; | ||
} | ||
} | ||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters