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
implement publish note dialog
ammarahm-ed0d8b87928027
diff --git a/apps/mobile/src/components/PublishNoteDialog/index.js b/apps/mobile/src/components/PublishNoteDialog/index.jsindex 47299b498..689d0add9 100644--- a/apps/mobile/src/components/PublishNoteDialog/index.js+++ b/apps/mobile/src/components/PublishNoteDialog/index.js@@ -1,5 +1,10 @@import React, {useEffect, useRef, useState} from 'react';-import {Clipboard, TouchableOpacity, View} from 'react-native';+import {+ ActivityIndicator,+ Clipboard,+ TouchableOpacity,+ View,+} from 'react-native';import Icon from 'react-native-vector-icons/MaterialCommunityIcons';import {useTracked} from '../../provider';import {@@ -33,7 +38,11 @@ const PublishNoteDialog = () => {const [selfDestruct, setSelfDestruct] = useState(false);const [isLocked, setIsLocked] = useState(false);const [note, setNote] = useState(null);- const publishUrl = `https://monograph.notesnook.com/${note?.publishId}`;+ const [publishing, setPublishing] = useState(false);+ const publishUrl =+ note &&+ `https://monograph.notesnook.com/${db?.monographs.monograph(note?.id)}`;+ const isPublished = note && db?.monographs.isPublished(note?.id);useEffect(() => {eSubscribeEvent(eOpenPublishNoteDialog, open);@@ -46,8 +55,13 @@ const PublishNoteDialog = () => {const open = item => {setNote(item);+ setPublishing(false);+ setSelfDestruct(false);+ setIsLocked(false);setVisible(true);+ passwordValue = null;};+useEffect(() => {if (visible) {actionSheetRef.current?.show();@@ -60,53 +74,63 @@ const PublishNoteDialog = () => {};const publishNote = async () => {- if (note?.id) {- if (isLocked && !passwordValue) return;- await db.monograph.update(note.id, {- selfDestruct: selfDestruct,- password: isLocked && passwordValue,+ if (publishing) return;+ setPublishing(true);+ try {+ if (note?.id) {+ if (isLocked && !passwordValue) return;+ await db.monographs.publish(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,+ ]);+ }+ } catch (e) {+ ToastEvent.show({+ heading: 'Could not publish note',+ message: e.message,+ type: 'error',+ context: 'local',});- 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,- ]);}+ setPublishing(false);};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,- ]);+ if (publishing) return;+ setPublishing(true);+ try {+ if (note?.id) {+ await db.monographs.unpublish(note.id);+ setNote(db.notes.note(note.id)?.data);+ Navigation.setRoutesToUpdate([+ Navigation.routeNames.Notes,+ Navigation.routeNames.NotesPage,+ Navigation.routeNames.Favorites,+ ]);+ }+ } catch (e) {+ ToastEvent.show({+ heading: 'Could not unpublish note',+ message: e.message,+ type: 'error',+ context: 'local',+ });}+ actionSheetRef.current?.hide();+ setPublishing(false);};return !visible ? null : (<ActionSheetWrappercentered={false}fwdRef={actionSheetRef}+ closeOnTouchBackdrop={!publishing}onClose={async () => {passwordValue = null;setVisible(false);@@ -124,176 +148,212 @@ const PublishNoteDialog = () => {} of a published note can view it.`}/>- {note.publishId && (+ {publishing ? (<Viewstyle={{- flexDirection: 'row',- alignItems: 'center',- marginTop: 15,- backgroundColor: colors.shade,- padding: 10,- borderRadius: 5,- borderWidth: 1,- borderColor: colors.accent,+ justifyContent: 'center',+ alignContent: 'center',+ height: 150,+ width: '100%',}}>- <View+ <ActivityIndicator size={25} color={colors.accent} />+ <Paragraphstyle={{- width: '100%',- flexShrink: 1,+ textAlign: 'center',}}>- <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) {}- }}+ Please wait...+ </Paragraph>+ </View>+ ) : (+ <>+ {isPublished && (+ <Viewstyle={{- marginTop: 5,- color: colors.accent,+ flexDirection: 'row',+ alignItems: 'center',+ marginTop: 15,+ backgroundColor: colors.shade,+ padding: 10,+ borderRadius: 5,+ borderWidth: 1,+ borderColor: colors.accent,}}>- <Icon name="open-in-new" /> Open in browser- </Paragraph>- </View>+ <View+ style={{+ width: '100%',+ flexShrink: 1,+ }}>+ <Heading size={SIZE.md}>This Note is published</Heading>+ <Paragraph numberOfLines={1}>{publishUrl}</Paragraph>- <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>- )}+ <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>- {isLocked ? (- <Input- onChangeText={value => (passwordValue = value)}- blurOnSubmit- secureTextEntry- placeholder="Enter Password"- />- ) : (- <Seperator />- )}+ <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>+ )}- <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'- }- />+ {isLocked ? (+ <Input+ onChangeText={value => (passwordValue = value)}+ blurOnSubmit+ secureTextEntry+ placeholder="Enter Password"+ />+ ) : (+ <Seperator />+ )}- <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={() => {+ if (publishing) return;+ setIsLocked(!isLocked);+ }}+ activeOpacity={0.9}+ style={{+ flexDirection: 'row',+ alignItems: 'center',+ marginBottom: 10,+ }}>+ <ActionIcon+ onPress={() => {+ if (publishing) return;+ setIsLocked(!isLocked);+ }}+ color={isLocked ? colors.accent : colors.icon}+ size={SIZE.lg}+ name={+ isLocked+ ? 'check-circle-outline'+ : 'checkbox-blank-circle-outline'+ }+ />- <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}>+ Password protection {isLocked ? 'enabled' : 'disabled'}+ </Heading>+ <Paragraph>+ Published note can only be viewed by someone with the+ password.+ </Paragraph>+ </View>+ </TouchableOpacity>- <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>+ <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%',- 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'}- />+ <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>- {note.publishId && (- <>- <Seperator half />+ <View+ style={{+ width: '100%',+ alignSelf: 'center',+ marginTop: 10,+ }}><Button- onPress={deletePublishedNote}+ onPress={publishNote}fontSize={SIZE.md}width="100%"height={50}- type="error"- title="Unpublish note"+ type="accent"+ title={isPublished ? 'Update published note' : 'Publish note'}/>- </>- )}- </View>++ {isPublished && (+ <>+ <Seperator half />+ <Button+ onPress={deletePublishedNote}+ fontSize={SIZE.md}+ width="100%"+ height={50}+ type="error"+ title="Unpublish note"+ />+ </>+ )}+ </View>+ </>+ )}++ <Paragraph+ color={colors.icon}+ size={SIZE.xs + 1}+ style={{+ textAlign: 'center',+ marginTop: 5,+ textDecorationLine: 'underline',+ }}+ onPress={async () => {+ try {+ await openLinkInBrowser(+ 'https://docs.notesnook.com/notesnook-monograph/',+ colors.accent,+ );+ } catch (e) {}+ }}>+ Learn more about Notesnook Monograph+ </Paragraph></View></ActionSheetWrapper>);