A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
add publish note sheet
Ammar Ahmed122460a66393
diff --git a/apps/mobile/src/components/Dialog/DialogContainer.js b/apps/mobile/src/components/Dialog/DialogContainer.jsindex f14b75888..dc449740e 100644--- a/apps/mobile/src/components/Dialog/DialogContainer.js+++ b/apps/mobile/src/components/Dialog/DialogContainer.js@@ -14,7 +14,7 @@ const DialogContainer = ({width, height, ...restProps}) => {style={{...getElevation(5),width: width || DDS.isTab ? 400 : '85%',- maxHeight: height || 350,+ maxHeight: height || 450,borderRadius: 5,backgroundColor: colors.bg,paddingHorizontal: 12,diff --git a/apps/mobile/src/components/DialogManager/index.js b/apps/mobile/src/components/DialogManager/index.jsindex 3d721f41b..8591b75f1 100644--- a/apps/mobile/src/components/DialogManager/index.js+++ b/apps/mobile/src/components/DialogManager/index.js@@ -41,6 +41,7 @@ import PendingDialog from '../Premium/PendingDialog';import PremiumDialog from '../Premium/PremiumDialog';import PremiumStatusDialog from '../Premium/PremiumStatusDialog';import ProgressDialog from '../ProgressDialog';+import PublishNoteDialog from '../PublishNoteDialog';import RateDialog from '../RateDialog';import RecoveryKeyDialog from '../RecoveryKeyDialog';import RestoreDialog from '../RestoreDialog';@@ -384,6 +385,7 @@ export class DialogManager extends Component {<RateDialog /><ImagePreview/><EditorSettings/>+ <PublishNoteDialog/></>);}diff --git a/apps/mobile/src/components/NoteItem/index.js b/apps/mobile/src/components/NoteItem/index.jsindex e707c988f..52dfd0ea8 100644--- a/apps/mobile/src/components/NoteItem/index.js+++ b/apps/mobile/src/components/NoteItem/index.js@@ -23,8 +23,8 @@ const NoteItem = ({item, isTrash}) => {isTrash ? false : true,isTrash? ['Remove', 'Restore']- : ['Add to', 'Share', 'Export', 'Delete', 'Copy'],- isTrash ? [] : ['Pin', 'Favorite', 'Add to Vault'],+ : ['Add to', 'Share', 'Export','Copy','Publish'],+ isTrash ? [] : ['Pin', 'Favorite', 'Vault','Delete','RemoveTopic'],);};diff --git a/apps/mobile/src/components/NotebookItem/index.js b/apps/mobile/src/components/NotebookItem/index.jsindex 3abc1a452..8bd87b0d7 100644--- a/apps/mobile/src/components/NotebookItem/index.js+++ b/apps/mobile/src/components/NotebookItem/index.js@@ -1,13 +1,13 @@import React from 'react';-import { TouchableOpacity, View } from 'react-native';+import {TouchableOpacity, View} from 'react-native';import Icon from 'react-native-vector-icons/MaterialCommunityIcons';-import { notesnook } from '../../../e2e/test.ids';-import { useTracked } from '../../provider';+import {notesnook} from '../../../e2e/test.ids';+import {useTracked} from '../../provider';import Navigation from '../../services/Navigation';-import { getTotalNotes, history } from '../../utils';-import { SIZE } from '../../utils/SizeUtils';-import { ActionIcon } from '../ActionIcon';-import { ActionSheetEvent } from '../DialogManager/recievers';+import {getTotalNotes, history} from '../../utils';+import {SIZE} from '../../utils/SizeUtils';+import {ActionIcon} from '../ActionIcon';+import {ActionSheetEvent} from '../DialogManager/recievers';import Heading from '../Typography/Heading';import Paragraph from '../Typography/Paragraph';@@ -25,7 +25,7 @@ export const NotebookItem = ({item, isTopic = false, notebookID, isTrash}) => {? []: item.type === 'topic'? ['Add Shortcut to Menu', 'Remove Shortcut from Menu']- : ['Pin', 'Add Shortcut to Menu', 'Remove Shortcut from Menu'];+ : ['Pin', 'Add Shortcut to Menu'];ActionSheetEvent(item, false, false, rowItems, columnItems, {notebookID: notebookID,@@ -117,7 +117,7 @@ export const NotebookItem = ({item, isTopic = false, notebookID, isTrash}) => {justifyContent: 'flex-start',alignItems: 'center',marginTop: 2.5,- minHeight:SIZE.md + 2+ minHeight: SIZE.md + 2,}}>{isTrash ? (<>diff --git a/apps/mobile/src/components/PublishNoteDialog/index.js b/apps/mobile/src/components/PublishNoteDialog/index.jsnew file mode 100644index 000000000..b929eb01f--- /dev/null+++ b/apps/mobile/src/components/PublishNoteDialog/index.js@@ -0,0 +1,313 @@+import React, {useEffect, useRef, useState} from 'react';+import {+ Clipboard,+ Linking,+ Platform,+ TouchableOpacity,+ View,+} from 'react-native';+import {+ eSubscribeEvent,+ eUnSubscribeEvent,+ ToastEvent,+} from '../../services/EventManager';+import {+ eClosePublishNoteDialog,+ eCloseRateDialog,+ eOpenPublishNoteDialog,+ eOpenRateDialog,+} from '../../utils/Events';+import {MMKV} from '../../utils/mmkv';+import {SIZE} from '../../utils/SizeUtils';+import ActionSheetWrapper from '../ActionSheetComponent/ActionSheetWrapper';+import {Button} from '../Button';+import DialogHeader from '../Dialog/dialog-header';+import Input from '../Input';+import Seperator from '../Seperator';+import Heading from '../Typography/Heading';+import Paragraph from '../Typography/Paragraph';++import Icon from 'react-native-vector-icons/MaterialCommunityIcons';+import {ActionIcon} from '../ActionIcon';+import {useTracked} from '../../provider';+import {db} from '../../utils/DB';+import Navigation from '../../services/Navigation';+import {openLinkInBrowser} from '../../utils/functions';++let passwordValue = null;+const PublishNoteDialog = () => {+ const [state] = useTracked();+ const colors = state.colors;+ const [visible, setVisible] = useState(false);+ const actionSheetRef = useRef();+ const [selfDestruct, setSelfDestruct] = useState(true);+ const [isLocked, setIsLocked] = useState(false);+ const [note, setNote] = useState(null);+ const publishUrl = `https://monograph.notesnook.com/${note?.publishId}`;++ useEffect(() => {+ eSubscribeEvent(eOpenPublishNoteDialog, open);+ eSubscribeEvent(eClosePublishNoteDialog, close);+ return () => {+ eUnSubscribeEvent(eOpenPublishNoteDialog, open);+ eUnSubscribeEvent(eClosePublishNoteDialog, close);+ };+ }, []);++ const open = (item) => {+ setNote(item);+ setVisible(true);+ };+ useEffect(() => {+ if (visible) {+ actionSheetRef.current?.show();+ }+ }, [visible]);++ const close = () => {+ passwordValue = null;+ actionSheetRef.current?.hide();+ };++ const publishNote = async () => {+ if (note?.id) {+ if (isLocked && !passwordValue) return;+ await db.monograph.update(note.id, {+ selfDestruct: selfDestruct,+ password: isLocked && passwordValue,+ });+ setNote(db.notes.note(note.id)?.data);+ Navigation.setRoutesToUpdate([+ Navigation.routeNames.Notes,+ Navigation.routeNames.NotesPage,+ Navigation.routeNames.Favorites,+ ]);+ }+ };++ const updateNote = async () => {+ if (note?.id) {+ if (isLocked && !passwordValue) return;+ await db.monograph.update(note.id, {+ selfDestruct: selfDestruct,+ password: isLocked && passwordValue,+ });+ setNote(db.notes.note(note.id)?.data);+ Navigation.setRoutesToUpdate([+ Navigation.routeNames.Notes,+ Navigation.routeNames.NotesPage,+ Navigation.routeNames.Favorites,+ ]);+ }+ };++ const deletePublishedNote = async () => {+ if (note?.id) {+ await db.monograph.unpublish(note.id);+ setNote(db.notes.note(note.id)?.data);+ Navigation.setRoutesToUpdate([+ Navigation.routeNames.Notes,+ Navigation.routeNames.NotesPage,+ Navigation.routeNames.Favorites,+ ]);+ }+ };++ return !visible ? null : (+ <ActionSheetWrapper+ centered={false}+ fwdRef={actionSheetRef}+ onClose={async () => {++ passwordValue = null;+ setVisible(false);+ }}>+ <View+ style={{+ width: '100%',+ alignSelf: 'center',+ paddingHorizontal: 12,+ }}>+ <DialogHeader+ title="Publish note"+ paragraph={`Anyone with the link${+ isLocked ? ' and password' : ''+ } of a published note can view it.`}+ />++ {note.publishId && (+ <View+ style={{+ flexDirection: 'row',+ alignItems: 'center',+ marginTop: 15,+ backgroundColor: colors.shade,+ padding: 10,+ borderRadius: 5,+ borderWidth: 1,+ borderColor: colors.accent,+ }}>+ <View+ style={{+ width: '100%',+ flexShrink: 1,+ }}>+ <Heading size={SIZE.md}>This Note is published</Heading>+ <Paragraph numberOfLines={1}>{publishUrl}</Paragraph>++ <Paragraph+ onPress={async () => {+ try {+ await openLinkInBrowser(publishUrl, colors.accent);+ } catch (e) {}+ }}+ style={{+ marginTop: 5,+ color: colors.accent,+ }}>+ <Icon name="open-in-new" /> Open in browser+ </Paragraph>+ </View>++ <ActionIcon+ onPress={() => {+ Clipboard.setString(publishUrl);+ ToastEvent.show({+ heading: 'Note publish url copied',+ type: 'success',+ context: 'local',+ });+ }}+ color={colors.icon}+ size={SIZE.lg}+ name="content-copy"+ />+ </View>+ )}++ {isLocked ? (+ <Input+ onChangeText={value => (passwordValue = value)}+ blurOnSubmit+ secureTextEntry+ placeholder="Enter Password"+ />+ ) : (+ <Seperator />+ )}++ <TouchableOpacity+ onPress={() => {+ setIsLocked(!isLocked);+ }}+ activeOpacity={0.9}+ style={{+ flexDirection: 'row',+ alignItems: 'center',+ marginBottom: 10,+ }}>+ <ActionIcon+ onPress={() => {+ setIsLocked(!isLocked);+ }}+ color={isLocked ? colors.accent : colors.icon}+ size={SIZE.lg}+ name={+ isLocked+ ? 'check-circle-outline'+ : 'checkbox-blank-circle-outline'+ }+ />++ <View+ style={{+ width: '100%',+ flexShrink: 1,+ }}>+ <Heading size={SIZE.md}>+ Password protection {isLocked ? 'enabled' : 'disabled'}+ </Heading>+ <Paragraph>+ Published note can only be viewed by someone with the password.+ </Paragraph>+ </View>+ </TouchableOpacity>++ <TouchableOpacity+ onPress={() => {+ setSelfDestruct(!selfDestruct);+ }}+ activeOpacity={0.9}+ style={{+ flexDirection: 'row',+ alignItems: 'center',+ }}>+ <ActionIcon+ onPress={() => {+ setSelfDestruct(!selfDestruct);+ }}+ color={selfDestruct ? colors.accent : colors.icon}+ size={SIZE.lg}+ name={+ selfDestruct+ ? 'check-circle-outline'+ : 'checkbox-blank-circle-outline'+ }+ />++ <View+ style={{+ width: '100%',+ flexShrink: 1,+ }}>+ <Heading size={SIZE.md}>+ Self destruct {selfDestruct ? 'enabled' : 'disabled'}+ </Heading>+ <Paragraph>+ Published note link will be automatically deleted once it is+ viewed by someone.+ </Paragraph>+ </View>+ </TouchableOpacity>++ <View+ style={{+ width: '100%',+ alignSelf: 'center',+ marginTop: 10,+ }}>+ <Button+ onPress={async () => {+ if (note.publishId) {+ updateNote();+ } else {+ publishNote();+ }+ }}+ fontSize={SIZE.md}+ width="100%"+ height={50}+ type="accent"+ title={note.publishId ? 'Update published note' : 'Publish note'}+ />++ {note.publishId && (+ <>+ <Seperator half />+ <Button+ onPress={deletePublishedNote}+ fontSize={SIZE.md}+ width="100%"+ height={50}+ type="error"+ title="Unpublish note"+ />+ </>+ )}+ </View>+ </View>+ </ActionSheetWrapper>+ );+};++export default PublishNoteDialog;diff --git a/apps/mobile/src/utils/Events.js b/apps/mobile/src/utils/Events.jsindex 294ec9c8e..e632e5f29 100644--- a/apps/mobile/src/utils/Events.js+++ b/apps/mobile/src/utils/Events.js@@ -123,4 +123,7 @@ export const eCloseJumpToDialog = '562';export const eShowGetPremium = '563';export const eOpenRateDialog = '564';-export const eCloseRateDialog = '565';\ No newline at end of file+export const eCloseRateDialog = '565';++export const eOpenPublishNoteDialog = '566';+export const eClosePublishNoteDialog = '567';\ No newline at end of file