Files
notesnook/apps/mobile/share/share.js

886 lines
27 KiB
JavaScript
Raw Permalink Normal View History

/*
This file is part of the Notesnook project (https://notesnook.com/)
2023-01-16 13:44:52 +05:00
Copyright (C) 2023 Streetwriters (Private) Limited
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-08-30 16:13:11 +05:00
import ShareExtension from "@ammarahmed/react-native-share-extension";
import { getPreviewData } from "@flyerhq/react-native-link-preview";
import {
formatBytes,
isFeatureAvailable,
useIsFeatureAvailable
} from "@notesnook/common";
2024-09-23 15:18:44 +05:00
import { isImage } from "@notesnook/core";
import { useThemeColors } from "@notesnook/theme";
import React, { useCallback, useEffect, useRef, useState } from "react";
2022-07-07 14:33:54 +05:00
import {
ActivityIndicator,
Alert,
Dimensions,
Image,
2022-07-07 14:33:54 +05:00
Keyboard,
Platform,
SafeAreaView,
ScrollView,
Text,
TextInput,
2022-07-07 14:33:54 +05:00
TouchableOpacity,
2023-04-04 14:25:21 +05:00
View,
useWindowDimensions
} from "react-native";
import RNFetchBlob from "react-native-blob-util";
import { SafeAreaProvider } from "react-native-safe-area-context";
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
import isURL from "validator/lib/isURL";
2024-02-11 00:02:00 +05:00
import { DatabaseLogger, db } from "../app/common/database";
2024-12-24 11:50:17 +05:00
import { Storage } from "../app/common/database/storage";
2023-11-30 12:20:22 +05:00
import { Button } from "../app/components/ui/button";
import Heading from "../app/components/ui/typography/heading";
import Paragraph from "../app/components/ui/typography/paragraph";
import { useDBItem } from "../app/hooks/use-db-item";
import { eSendEvent } from "../app/services/event-manager";
import { FILE_SIZE_LIMIT, IMAGE_SIZE_LIMIT } from "../app/utils/constants";
import { eOnLoadNote } from "../app/utils/events";
import { NoteBundle } from "../app/utils/note-bundle";
import { defaultBorderRadius, AppFontSize } from "../app/utils/size";
2023-11-30 11:21:12 +05:00
import { AddNotebooks } from "./add-notebooks";
import { AddTags } from "./add-tags";
import { Editor } from "./editor";
import { HtmlLoadingWebViewAgent, fetchHandle } from "./fetch-webview";
import { Search } from "./search";
import { initDatabase, useShareStore } from "./store";
const getLinkPreview = (url) => {
2022-07-07 14:33:54 +05:00
return getPreviewData(url, 5000);
};
async function sanitizeHtml(site) {
try {
2023-09-18 07:06:58 +05:00
let html = await fetchHandle.current?.processUrl(site);
return html;
2022-07-07 14:33:54 +05:00
} catch (e) {
return "";
2022-07-07 14:33:54 +05:00
}
}
function makeHtmlFromUrl(url) {
return `<a href='${url}' target='_blank'>${url}</a>`;
2022-07-07 14:33:54 +05:00
}
function makeHtmlFromPlainText(text) {
if (!text) return "";
2022-07-07 14:33:54 +05:00
return `<p>${text
.replace(/[\n]+/g, "\n")
.replace(/(?:\r\n|\r|\n)/g, "</p><p>")}</p>`;
2022-07-07 14:33:54 +05:00
}
let defaultNote = {
title: null,
id: null,
content: {
type: "tiptap",
2022-07-07 14:33:54 +05:00
data: null
}
};
const modes = {
1: {
type: "text",
title: "Plain text",
icon: "card-text-outline"
2022-07-07 14:33:54 +05:00
},
2: {
type: "clip",
title: "Web clip",
icon: "web"
2022-07-07 14:33:54 +05:00
},
3: {
type: "link",
title: "Link",
icon: "link"
2022-07-07 14:33:54 +05:00
}
};
2023-11-30 12:20:22 +05:00
const ShareView = () => {
global: implement the new theme engine (#2196) * mobile: theme * theme: add theme engine * mobile: migrate app colors to new theme engine * mobile: fixed some colors * mobile: fix colors * mobile: store theme info in store * theme: `ColorsType` -> `Variants` * theme: use explicit return type for `useThemeColors` * theme: add `backdrop` color * mobile: `const colors` -> `const {colors} * theme: add default pitch-black theme * mobile: manage theme state via theme-engine * mobile: add theme scopes * mobile: commit * mobile: fix button width on applock screen * mobile: fix typings * mobile: fix theme definition * web: add partial support for custom themes only context menus & popups are left. * theme: add dialog & sheet scopes * global: sync with master branch and make everything work again * mobile: fix theme-engine usage in editor & app * mobile: fix colors * mobile: fix colors * mobile: cleanup * mobile: fix status bar color incorrect on entering foreground * mobile: fix dark color scheme * web: move emotion theme provider to @notesnook/theme * editor: add support for theme enging * web: adjust hover & focus colors on list item * mobile: migrate share ext to theme engine * mobile: fix editor theme provider * clipper: add support for the new theme engine * mobile: fix statusbar color on switch from bg * misc: fix build * mobile: fix build * misc: fix colors * mobile: fix theme colors * mobile: fix bottom padding * server: add theme server * theme: add previewColors * server: support themes query pagination * mobile: add client from theme server * server: reset cache on sync repo * server: fix types * server: show ip & port on start server * server: theme updates * web: finalize new theme engine on web * editor: fix build * global: fix @emotion/react version to 11.11.1 * editor: update katex patch * web: fix imports * global: fix @trpc/* versions * global: a huge set of changes 1. get rid of ThemeVariant. All variants can now be accessed anywhere. 2. remove unnecessary button variants 3. make buttons more responsive 4. implement themes server * web: add support for theme search and theme switching * global: update lockfiles * mobile: fix error * theme: use vite-plugin-react to start theme server * web: add support for auto updating themes * mobile: update theme selector * mobile: update theme if new verison available * theme: add `isomorphic-fetch` package * global: update lockfiles * web: add theme details dialog * setup: add scope for themes server in bootstrap script * web: add production server url * web: update lockfile * web: update lockfile * mobile: remove `react-native-blob-util` * web: add support for endless scrolling in themes * web: bring back dark/light mode option in settings * web: fix colors in places * theme: add selected variant * global: use single typescript version across the projects * web: fix sort & group options not having submenus * web: apply selected variant where appropriate * ui: use unique id for all menu items * config: add ui scope for commits * theme: export button variant creation fn * web: fix only 1 theme showing in theme selector * web: fix navigation item hover & other colors * mobile: update theme * editor: fix toolbar group alignments * editor: set theme provider at app level * theme: use scope name to get current scope * mobile: fix color usage in message card * theme: remove caching * editor: bring back icons in table menus * theme: use zustand to manage theme engine state * web: fix login/signup theming * mobile: fix webpack build * misc: remove ThemeProvider usage * editor: adjust theming and styling of editor toolbar * mobile: refactor * editor: fix toolbar group padding everywhere * web: fix settings sidebar is not scrollable * web: add loading indicator for themes loading * mobile: fix warning * mobile: fix ui issues * web: fix Loader errors on build * theme: add getPreviewColors & validateTheme * theme: fix theme validation * mobile: load theme from file * mobile: fix share extension crash * mobile: rename state * theme: add sourceURL property * theme: refactor theme-engine * web: add support for loading theme from file * web: improve button hover interaction * mobile: fix floating button color * mobile: update theme * mobile: fix border radius of context menu * mobile: set sheet overlay color to theme backdrop * mobile: set sidemenu backdrop to theme backdrop --------- Co-authored-by: Abdullah Atta <abdullahatta@streetwriters.co>
2023-08-01 12:07:21 +05:00
const { colors } = useThemeColors();
const appendNoteId = useShareStore((state) => state.appendNote);
2022-07-07 14:33:54 +05:00
const [note, setNote] = useState({ ...defaultNote });
const noteContent = useRef("");
const noteTitle = useRef("");
2022-07-07 14:33:54 +05:00
const [loading, setLoading] = useState(false);
const [loadingExtension, setLoadingExtension] = useState(true);
const fullQualityImages = useIsFeatureAvailable("fullQualityImages");
2022-07-07 14:33:54 +05:00
const [rawData, setRawData] = useState({
type: null,
value: null
});
const inputRef = useRef(null);
2022-07-07 14:33:54 +05:00
const [mode, setMode] = useState(1);
const keyboardHeight = useRef(0);
const { width, height } = useWindowDimensions();
2023-09-18 07:06:58 +05:00
const [loadingPage, setLoadingPage] = useState(false);
const editorRef = useRef();
const [searchMode, setSearchMode] = useState(null);
const [rawFiles, setRawFiles] = useState([]);
2022-07-07 14:33:54 +05:00
const [kh, setKh] = useState(0);
const [compress, setCompress] = useState(true);
globalThis["IS_SHARE_EXTENSION"] = true;
const onKeyboardDidShow = (event) => {
let height = Dimensions.get("screen").height - event.endCoordinates.screenY;
keyboardHeight.current = height;
setKh(height);
2022-07-07 14:33:54 +05:00
};
const onKeyboardDidHide = () => {
keyboardHeight.current = 0;
setKh(0);
};
useEffect(() => {
let keyboardDidShow = Keyboard.addListener(
"keyboardDidShow",
onKeyboardDidShow
);
let keyboardDidHide = Keyboard.addListener(
"keyboardDidHide",
onKeyboardDidHide
);
2022-07-07 14:33:54 +05:00
return () => {
keyboardDidShow?.remove();
keyboardDidHide?.remove();
};
}, []);
useEffect(() => {
if (!fullQualityImages?.isAllowed) {
setCompress(true);
}
}, [fullQualityImages]);
2022-07-07 14:33:54 +05:00
const showLinkPreview = async (note, link) => {
let _note = note;
_note.content.data = makeHtmlFromUrl(link);
try {
let preview = await getLinkPreview(link);
_note.title = preview.title;
} catch (e) {
console.log(e);
}
return note;
};
const loadData = useCallback(
async (isEditor) => {
try {
if (noteContent.current) {
onLoad();
return;
}
defaultNote.content.data = null;
setNote({ ...defaultNote });
const data = await ShareExtension.data();
if (!data || data.length === 0) {
setRawData({
value: ""
});
if (isEditor) {
setTimeout(() => {
editorRef.current?.focus();
}, 300);
2022-07-07 14:33:54 +05:00
}
return;
}
let note = { ...defaultNote };
for (let item of data) {
if (item.type === "text") {
setRawData(item);
if (isURL(item.value)) {
note = await showLinkPreview(note, item.value);
} else {
note.content.data = makeHtmlFromPlainText(item.value);
}
noteContent.current = note.content.data;
} else if (item.type === "extras") {
for (const key in item) {
if (!key) continue;
if (key.includes("TITLE") || key.includes("SUBJECT")) {
note.title = item[key];
noteTitle.current = note.title;
inputRef.current?.setNativeProps?.({
text: noteTitle.current
});
}
if (key.includes("TEXT") && !note.content.data) {
note.content.data = item[key];
noteContent.current = item[key];
}
}
} else {
const user = await db.user.getUser();
if (user) {
const feature = await isFeatureAvailable(
"fileSize",
item.size || 0
);
if (!feature.isAllowed) {
continue;
}
setRawFiles((files) => {
const index = files.findIndex(
(file) => file.name === item.name
);
if (index === -1) {
files.push(item);
return [...files];
} else {
return files;
}
});
}
}
2022-07-07 14:33:54 +05:00
}
onLoad();
setNote({ ...note });
} catch (e) {
console.error(e);
}
},
[onLoad]
);
2022-07-07 14:33:54 +05:00
const onLoad = useCallback(() => {
eSendEvent(eOnLoadNote + "shareEditor", {
id: null,
content: {
type: "tiptap",
data: noteContent.current
},
forced: true
});
}, []);
2022-07-07 14:33:54 +05:00
useEffect(() => {
(async () => {
2024-02-11 00:02:00 +05:00
try {
await initDatabase();
setLoadingExtension(false);
loadData();
useShareStore.getState().restore();
} catch (e) {
DatabaseLogger.error(e);
}
2022-07-07 14:33:54 +05:00
})();
2022-09-01 16:34:26 +05:00
}, [loadData]);
2022-07-07 14:33:54 +05:00
const close = async () => {
setNote({ ...defaultNote });
setLoadingExtension(true);
2023-11-30 12:20:22 +05:00
ShareExtension.close();
2022-07-07 14:33:54 +05:00
};
const onPress = async () => {
setLoading(true);
if (!noteContent.current && rawFiles.length === 0 && !noteTitle.current) {
setLoading(false);
return;
}
2022-07-07 14:33:54 +05:00
let noteData;
if (appendNoteId) {
if (!(await db.notes.exists(appendNoteId))) {
useShareStore.getState().setAppendNote(null);
Alert.alert("The note you are trying to append to has been deleted.");
setLoading(false);
return;
}
const note = await db.notes.note(appendNoteId);
let rawContent = await db.content.get(note.contentId);
noteData = {
2022-07-07 14:33:54 +05:00
content: {
data: (rawContent?.data || "") + "<br/>" + noteContent.current,
type: "tiptap"
2022-07-07 14:33:54 +05:00
},
id: note.id,
sessionId: Date.now()
2022-07-07 14:33:54 +05:00
};
} else {
noteData = { ...note };
noteData.content.data = noteContent.current;
noteData.sessionId = Date.now();
noteData.title = noteTitle.current;
2022-07-07 14:33:54 +05:00
}
try {
await NoteBundle.createNotes({
files: rawFiles,
note: noteData,
notebooks: useShareStore.getState().selectedNotebooks,
tags: useShareStore.getState().selectedTags,
compress
});
if (!globalThis["IS_MAIN_APP_RUNNING"]) {
await db.sync({ type: "send", force: false });
} else {
console.log("main app running, skipping sync");
}
} catch (e) {
DatabaseLogger.error(e, "Error adding notes from share extension");
}
await Storage.write("notesAddedFromIntent", "added");
2022-07-07 14:33:54 +05:00
close();
setLoading(false);
};
const changeMode = async (m) => {
2022-07-07 14:33:54 +05:00
setMode(m);
setLoading(true);
try {
if (m === 2) {
2023-09-18 07:06:58 +05:00
setLoadingPage(true);
2023-09-21 18:02:47 +05:00
setTimeout(async () => {
let html = await sanitizeHtml(rawData.value);
noteContent.current = html;
setLoadingPage(false);
onLoad();
setNote((note) => {
note.content.data = html;
return { ...note };
});
}, 300);
2022-07-07 14:33:54 +05:00
} else {
2023-09-21 18:02:47 +05:00
setLoadingPage(false);
2022-07-07 14:33:54 +05:00
let html = isURL(rawData.value)
? makeHtmlFromUrl(rawData.value)
: makeHtmlFromPlainText(rawData.value);
setNote((note) => {
2022-07-07 14:33:54 +05:00
note.content.data = html;
noteContent.current = html;
onLoad();
return { ...note };
});
}
} catch (e) {
console.error(e);
2022-07-07 14:33:54 +05:00
} finally {
setLoading(false);
}
};
const onLoadEditor = useCallback(() => {
Storage.write("shareExtensionOpened", "opened");
loadData(true);
}, [loadData]);
const onRemoveFile = (item) => {
const index = rawFiles.findIndex((file) => file.name === item.name);
if (index > -1) {
setRawFiles((state) => {
const files = [...state];
files.splice(index);
return files;
});
RNFetchBlob.fs.unlink(item.value).catch(console.log);
}
};
2023-04-05 02:12:27 +05:00
const WrapperView = Platform.OS === "android" ? View : ScrollView;
2022-07-07 14:33:54 +05:00
return loadingExtension ? null : (
<SafeAreaView
style={{
width: width > 500 ? 500 : width,
2023-11-30 12:20:22 +05:00
height: height - kh,
alignSelf: "center",
justifyContent: "flex-end",
overflow: "hidden"
2022-07-07 14:33:54 +05:00
}}
>
2023-09-21 18:02:47 +05:00
{loadingPage ? <HtmlLoadingWebViewAgent /> : null}
2023-09-18 07:06:58 +05:00
2023-11-30 12:20:22 +05:00
<TouchableOpacity
activeOpacity={1}
onPress={() => {
if (searchMode) {
setSearchMode(null);
} else {
close();
}
}}
style={{
width: "100%",
height: "100%",
position: "absolute"
}}
>
2022-07-07 14:33:54 +05:00
<View
style={{
width: "100%",
height: "100%",
2023-11-30 12:20:22 +05:00
backgroundColor: "white",
opacity: 0.01
2022-07-07 14:33:54 +05:00
}}
2023-11-30 12:20:22 +05:00
/>
<View />
</TouchableOpacity>
2022-07-07 14:33:54 +05:00
{searchMode ? (
2022-07-07 14:33:54 +05:00
<Search
getKeyboardHeight={() => keyboardHeight.current}
mode={searchMode}
2022-07-07 14:33:54 +05:00
close={() => {
setSearchMode(null);
2022-07-07 14:33:54 +05:00
}}
/>
) : null}
2023-04-05 02:12:27 +05:00
<WrapperView
2022-07-07 14:33:54 +05:00
style={{
paddingVertical: 12,
global: implement the new theme engine (#2196) * mobile: theme * theme: add theme engine * mobile: migrate app colors to new theme engine * mobile: fixed some colors * mobile: fix colors * mobile: store theme info in store * theme: `ColorsType` -> `Variants` * theme: use explicit return type for `useThemeColors` * theme: add `backdrop` color * mobile: `const colors` -> `const {colors} * theme: add default pitch-black theme * mobile: manage theme state via theme-engine * mobile: add theme scopes * mobile: commit * mobile: fix button width on applock screen * mobile: fix typings * mobile: fix theme definition * web: add partial support for custom themes only context menus & popups are left. * theme: add dialog & sheet scopes * global: sync with master branch and make everything work again * mobile: fix theme-engine usage in editor & app * mobile: fix colors * mobile: fix colors * mobile: cleanup * mobile: fix status bar color incorrect on entering foreground * mobile: fix dark color scheme * web: move emotion theme provider to @notesnook/theme * editor: add support for theme enging * web: adjust hover & focus colors on list item * mobile: migrate share ext to theme engine * mobile: fix editor theme provider * clipper: add support for the new theme engine * mobile: fix statusbar color on switch from bg * misc: fix build * mobile: fix build * misc: fix colors * mobile: fix theme colors * mobile: fix bottom padding * server: add theme server * theme: add previewColors * server: support themes query pagination * mobile: add client from theme server * server: reset cache on sync repo * server: fix types * server: show ip & port on start server * server: theme updates * web: finalize new theme engine on web * editor: fix build * global: fix @emotion/react version to 11.11.1 * editor: update katex patch * web: fix imports * global: fix @trpc/* versions * global: a huge set of changes 1. get rid of ThemeVariant. All variants can now be accessed anywhere. 2. remove unnecessary button variants 3. make buttons more responsive 4. implement themes server * web: add support for theme search and theme switching * global: update lockfiles * mobile: fix error * theme: use vite-plugin-react to start theme server * web: add support for auto updating themes * mobile: update theme selector * mobile: update theme if new verison available * theme: add `isomorphic-fetch` package * global: update lockfiles * web: add theme details dialog * setup: add scope for themes server in bootstrap script * web: add production server url * web: update lockfile * web: update lockfile * mobile: remove `react-native-blob-util` * web: add support for endless scrolling in themes * web: bring back dark/light mode option in settings * web: fix colors in places * theme: add selected variant * global: use single typescript version across the projects * web: fix sort & group options not having submenus * web: apply selected variant where appropriate * ui: use unique id for all menu items * config: add ui scope for commits * theme: export button variant creation fn * web: fix only 1 theme showing in theme selector * web: fix navigation item hover & other colors * mobile: update theme * editor: fix toolbar group alignments * editor: set theme provider at app level * theme: use scope name to get current scope * mobile: fix color usage in message card * theme: remove caching * editor: bring back icons in table menus * theme: use zustand to manage theme engine state * web: fix login/signup theming * mobile: fix webpack build * misc: remove ThemeProvider usage * editor: adjust theming and styling of editor toolbar * mobile: refactor * editor: fix toolbar group padding everywhere * web: fix settings sidebar is not scrollable * web: add loading indicator for themes loading * mobile: fix warning * mobile: fix ui issues * web: fix Loader errors on build * theme: add getPreviewColors & validateTheme * theme: fix theme validation * mobile: load theme from file * mobile: fix share extension crash * mobile: rename state * theme: add sourceURL property * theme: refactor theme-engine * web: add support for loading theme from file * web: improve button hover interaction * mobile: fix floating button color * mobile: update theme * mobile: fix border radius of context menu * mobile: set sheet overlay color to theme backdrop * mobile: set sidemenu backdrop to theme backdrop --------- Co-authored-by: Abdullah Atta <abdullahatta@streetwriters.co>
2023-08-01 12:07:21 +05:00
backgroundColor: colors.primary.background,
display: searchMode ? "none" : "flex",
2023-04-04 14:25:21 +05:00
borderTopRightRadius: Platform.OS === "ios" ? 10 : 15,
2023-04-05 02:12:27 +05:00
borderTopLeftRadius: Platform.OS === "ios" ? 10 : 15,
maxHeight: Platform.OS === "android" ? undefined : "100%"
2022-07-07 14:33:54 +05:00
}}
>
<ScrollView>
2022-07-07 14:33:54 +05:00
<View
style={{
maxHeight: "100%"
2022-07-07 14:33:54 +05:00
}}
>
<View
style={{
width: "100%"
2022-07-07 14:33:54 +05:00
}}
>
<View
style={{
minHeight: 100,
backgroundColor: colors.primary.background,
overflow: "hidden"
}}
>
<View
style={{
justifyContent: "space-between",
flexDirection: "row",
alignItems: "center",
borderBottomWidth: 1,
paddingBottom: 12,
borderBottomColor: colors.secondary.background,
paddingHorizontal: 12,
gap: 10
}}
>
{appendNoteId ? (
<Heading
style={{
flexShrink: 1,
flexGrow: 1,
fontFamily: "Inter-SemiBold",
fontSize: AppFontSize.lg,
paddingBottom: 0,
paddingTop: 0
}}
>
Save note
</Heading>
) : (
<TextInput
placeholder="Enter note title"
ref={inputRef}
style={{
flexShrink: 1,
flexGrow: 1,
fontFamily: "Inter-SemiBold",
fontSize: AppFontSize.lg,
paddingBottom: 0,
paddingTop: 0,
color: colors.primary.heading
}}
onChangeText={(value) => {
noteTitle.current = value;
}}
defaultValue={noteTitle.current}
blurOnSubmit={false}
onSubmitEditing={() => {
editorRef.current.focus();
}}
/>
)}
<Button
title="Done"
type="accent"
loading={loading}
onPress={onPress}
/>
</View>
{rawFiles?.length > 0 ? (
<View
style={{
paddingHorizontal: 12,
paddingVertical: 12,
backgroundColor: colors.secondary.background
}}
global: implement the new theme engine (#2196) * mobile: theme * theme: add theme engine * mobile: migrate app colors to new theme engine * mobile: fixed some colors * mobile: fix colors * mobile: store theme info in store * theme: `ColorsType` -> `Variants` * theme: use explicit return type for `useThemeColors` * theme: add `backdrop` color * mobile: `const colors` -> `const {colors} * theme: add default pitch-black theme * mobile: manage theme state via theme-engine * mobile: add theme scopes * mobile: commit * mobile: fix button width on applock screen * mobile: fix typings * mobile: fix theme definition * web: add partial support for custom themes only context menus & popups are left. * theme: add dialog & sheet scopes * global: sync with master branch and make everything work again * mobile: fix theme-engine usage in editor & app * mobile: fix colors * mobile: fix colors * mobile: cleanup * mobile: fix status bar color incorrect on entering foreground * mobile: fix dark color scheme * web: move emotion theme provider to @notesnook/theme * editor: add support for theme enging * web: adjust hover & focus colors on list item * mobile: migrate share ext to theme engine * mobile: fix editor theme provider * clipper: add support for the new theme engine * mobile: fix statusbar color on switch from bg * misc: fix build * mobile: fix build * misc: fix colors * mobile: fix theme colors * mobile: fix bottom padding * server: add theme server * theme: add previewColors * server: support themes query pagination * mobile: add client from theme server * server: reset cache on sync repo * server: fix types * server: show ip & port on start server * server: theme updates * web: finalize new theme engine on web * editor: fix build * global: fix @emotion/react version to 11.11.1 * editor: update katex patch * web: fix imports * global: fix @trpc/* versions * global: a huge set of changes 1. get rid of ThemeVariant. All variants can now be accessed anywhere. 2. remove unnecessary button variants 3. make buttons more responsive 4. implement themes server * web: add support for theme search and theme switching * global: update lockfiles * mobile: fix error * theme: use vite-plugin-react to start theme server * web: add support for auto updating themes * mobile: update theme selector * mobile: update theme if new verison available * theme: add `isomorphic-fetch` package * global: update lockfiles * web: add theme details dialog * setup: add scope for themes server in bootstrap script * web: add production server url * web: update lockfile * web: update lockfile * mobile: remove `react-native-blob-util` * web: add support for endless scrolling in themes * web: bring back dark/light mode option in settings * web: fix colors in places * theme: add selected variant * global: use single typescript version across the projects * web: fix sort & group options not having submenus * web: apply selected variant where appropriate * ui: use unique id for all menu items * config: add ui scope for commits * theme: export button variant creation fn * web: fix only 1 theme showing in theme selector * web: fix navigation item hover & other colors * mobile: update theme * editor: fix toolbar group alignments * editor: set theme provider at app level * theme: use scope name to get current scope * mobile: fix color usage in message card * theme: remove caching * editor: bring back icons in table menus * theme: use zustand to manage theme engine state * web: fix login/signup theming * mobile: fix webpack build * misc: remove ThemeProvider usage * editor: adjust theming and styling of editor toolbar * mobile: refactor * editor: fix toolbar group padding everywhere * web: fix settings sidebar is not scrollable * web: add loading indicator for themes loading * mobile: fix warning * mobile: fix ui issues * web: fix Loader errors on build * theme: add getPreviewColors & validateTheme * theme: fix theme validation * mobile: load theme from file * mobile: fix share extension crash * mobile: rename state * theme: add sourceURL property * theme: refactor theme-engine * web: add support for loading theme from file * web: improve button hover interaction * mobile: fix floating button color * mobile: update theme * mobile: fix border radius of context menu * mobile: set sheet overlay color to theme backdrop * mobile: set sidemenu backdrop to theme backdrop --------- Co-authored-by: Abdullah Atta <abdullahatta@streetwriters.co>
2023-08-01 12:07:21 +05:00
>
<Paragraph
style={{ marginBottom: 6 }}
color={colors.primary.paragraph}
>
Attaching {rawFiles.length} file(s):
</Paragraph>
<ScrollView horizontal>
{rawFiles.map((item) =>
isImage(item.type) || item.value?.endsWith(".png") ? (
<TouchableOpacity
onPress={() => onRemoveFile(item)}
key={item.name}
activeOpacity={0.9}
>
<Image
source={{
uri:
Platform.OS === "android"
? `file://${item.value}`
: item.value
}}
style={{
width: 100,
height: 100,
borderRadius: defaultBorderRadius,
backgroundColor: "black",
marginRight: 6
}}
resizeMode="cover"
/>
</TouchableOpacity>
) : (
<TouchableOpacity
activeOpacity={0.9}
key={item.name}
source={{
uri: `file://${item.value}`
}}
onPress={() => onRemoveFile(item)}
style={{
borderRadius: defaultBorderRadius,
backgroundColor: colors.secondary.background,
flexDirection: "row",
borderWidth: 1,
borderColor: colors.primary.border,
alignItems: "center",
paddingVertical: 5,
paddingHorizontal: 8,
marginRight: 6
}}
resizeMode="cover"
>
<Icon
color={colors.primary.icon}
size={15}
name="file"
/>
<Paragraph
size={AppFontSize.xs}
color={colors.primary.paragraph}
style={{
marginLeft: 4,
paddingRight: 8
}}
>
{item.name || item.value.split("/").pop()}
{item.size ? `(${formatBytes(item.size)})` : ""}
</Paragraph>
</TouchableOpacity>
)
)}
</ScrollView>
<Paragraph
color={colors.secondary.paragraph}
size={AppFontSize.xs}
style={{
marginTop: 6
}}
>
Tap to remove an attachment.
</Paragraph>
2024-12-24 11:50:17 +05:00
{rawFiles.some((item) => isImage(item.type)) ? (
<TouchableOpacity
activeOpacity={1}
style={{
2024-12-24 11:50:17 +05:00
flexDirection: "row",
alignSelf: "center",
alignItems: "center",
width: "100%",
marginTop: 6
}}
onPress={() => {
if (fullQualityImages?.isAllowed) {
setCompress(!compress);
}
}}
>
2024-12-24 11:50:17 +05:00
<Icon
size={20}
name={
compress
? "checkbox-marked"
: "checkbox-blank-outline"
}
color={
compress && fullQualityImages?.isAllowed
2024-12-24 11:50:17 +05:00
? colors.primary.accent
: colors.primary.icon
}
/>
<Text
style={{
flexShrink: 1,
marginLeft: 3,
fontSize: 12
}}
>
Compress image(s) (recommended)
</Text>
</TouchableOpacity>
) : null}
</View>
) : null}
<View
2022-07-07 14:33:54 +05:00
style={{
width: "100%",
height: rawFiles.length > 0 ? 100 : 200,
paddingBottom: 15,
marginBottom: 10,
borderBottomColor: colors.secondary.background,
borderBottomWidth: 1
2022-07-07 14:33:54 +05:00
}}
>
<SafeAreaProvider
style={{
flex: 1,
paddingTop: 10,
justifyContent: loadingPage ? "center" : undefined,
alignItems: loadingPage ? "center" : undefined
}}
>
{!loadingExtension && !loadingPage ? (
<>
<Editor
editorRef={editorRef}
onLoad={onLoadEditor}
onChange={(html) => {
noteContent.current = html;
}}
/>
</>
) : (
<>
{loadingPage ? (
<>
<ActivityIndicator color={colors.primary.accent} />
<Paragraph>Preparing web clip...</Paragraph>
</>
) : null}
</>
)}
</SafeAreaProvider>
</View>
2022-07-07 14:33:54 +05:00
{appendNoteId ? (
<AppendNote
id={appendNoteId}
onLoad={(title) => {
if (!noteTitle.current) {
noteTitle.current = title;
inputRef.current?.setNativeProps?.({
text: noteTitle.current
});
}
}}
/>
) : null}
2022-07-07 14:33:54 +05:00
<View
2022-07-07 14:33:54 +05:00
style={{
flexDirection: "row",
paddingHorizontal: 12,
width: "100%",
alignItems: "center"
2022-07-07 14:33:54 +05:00
}}
>
<Paragraph
style={{
marginRight: 10
}}
>
Clip Mode:
</Paragraph>
{rawData.value && isURL(rawData.value) ? (
<Button
type={mode === 2 ? "inverted" : "plain"}
icon={mode === 2 ? "radiobox-marked" : "radiobox-blank"}
onPress={() => changeMode(2)}
title={modes[2].title}
height={30}
style={{
paddingHorizontal: 6
}}
/>
) : null}
2022-07-07 14:33:54 +05:00
<Button
type={mode === 1 ? "inverted" : "plain"}
icon={mode === 1 ? "radiobox-marked" : "radiobox-blank"}
onPress={() => changeMode(1)}
title={modes[1].title}
2023-11-30 12:20:22 +05:00
height={30}
2022-07-07 14:33:54 +05:00
style={{
2023-11-30 12:20:22 +05:00
paddingHorizontal: 6
2022-07-07 14:33:54 +05:00
}}
/>
</View>
2022-07-07 14:33:54 +05:00
</View>
</View>
<View
2023-01-16 13:44:52 +05:00
style={{
width: "100%",
borderRadius: 10,
flexDirection: "column",
marginTop: 10,
alignSelf: "center",
alignItems: "center",
paddingHorizontal: 12,
gap: 10
2023-01-16 13:44:52 +05:00
}}
>
<Button
icon="plus"
onPress={() => {
useShareStore.getState().setAppendNote(null);
}}
type={!appendNoteId ? "transparent" : "plain"}
title="New note"
style={{
paddingHorizontal: 12,
height: 45,
width: "100%",
marginRight: 0,
borderWidth: 1,
borderColor: colors.secondary.background,
justifyContent: "flex-start"
}}
/>
<Button
icon="text-short"
onPress={() => {
setSearchMode("appendNote");
}}
type={appendNoteId ? "transparent" : "plain"}
title={`Append to a note`}
style={{
paddingHorizontal: 12,
height: 45,
width: "100%",
marginRight: 0,
borderWidth: 1,
borderColor: colors.secondary.background,
justifyContent: "flex-start"
}}
/>
2023-01-14 18:39:36 +05:00
{!appendNoteId ? (
<AddTags
onPress={() => {
setSearchMode("selectTags");
}}
/>
) : null}
{!appendNoteId ? (
<AddNotebooks
onPress={() => {
setSearchMode("selectNotebooks");
}}
/>
) : null}
</View>
<View
style={{
height: Platform.isPad ? 150 : Platform.OS === "ios" ? 110 : 0
}}
/>
</View>
</ScrollView>
2023-04-05 02:12:27 +05:00
</WrapperView>
2022-07-07 14:33:54 +05:00
</SafeAreaView>
);
};
const AppendNote = ({ id, onLoad }) => {
2023-11-30 12:20:22 +05:00
const { colors } = useThemeColors();
const [item] = useDBItem(id, "note");
2022-07-07 14:33:54 +05:00
useEffect(() => {
if (item?.title) {
onLoad?.(item.title);
}
}, [item?.title, onLoad]);
2023-11-30 12:20:22 +05:00
return !item ? null : (
<Paragraph
size={AppFontSize.xs}
2023-11-30 12:20:22 +05:00
color={colors.secondary.paragraph}
style={{
paddingHorizontal: 12,
marginBottom: 10,
flexWrap: "wrap"
}}
2022-07-07 14:33:54 +05:00
>
2023-11-30 12:20:22 +05:00
Above content will append to{" "}
<Paragraph
size={AppFontSize.xs}
2023-11-30 12:20:22 +05:00
style={{
color: colors.primary.accent,
fontWeight: "bold"
}}
>
{`"${item.title}"`}
</Paragraph>{" "}
. Click on {'"New note"'} to create a new note.
</Paragraph>
2022-07-07 14:33:54 +05:00
);
};
export default ShareView;