mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-25 04:32:31 +01:00
* 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>
381 lines
11 KiB
JavaScript
381 lines
11 KiB
JavaScript
/*
|
|
This file is part of the Notesnook project (https://notesnook.com/)
|
|
|
|
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/>.
|
|
*/
|
|
|
|
import React, { useCallback, useEffect } from "react";
|
|
import { BackHandler, Platform, View } from "react-native";
|
|
import { db } from "../../common/database";
|
|
import useGlobalSafeAreaInsets from "../../hooks/use-global-safe-area-insets";
|
|
import { ToastEvent } from "../../services/event-manager";
|
|
import Navigation from "../../services/navigation";
|
|
import SearchService from "../../services/search";
|
|
import useNavigationStore from "../../stores/use-navigation-store";
|
|
import { useSelectionStore } from "../../stores/use-selection-store";
|
|
import { useThemeColors } from "@notesnook/theme";
|
|
import { deleteItems } from "../../utils/functions";
|
|
import { tabBarRef } from "../../utils/global-refs";
|
|
import { SIZE } from "../../utils/size";
|
|
import { sleep } from "../../utils/time";
|
|
import { presentDialog } from "../dialog/functions";
|
|
import MoveNoteSheet from "../sheets/add-to";
|
|
import ExportNotesSheet from "../sheets/export-notes";
|
|
import { IconButton } from "../ui/icon-button";
|
|
import Heading from "../ui/typography/heading";
|
|
import ManageTagsSheet from "../sheets/manage-tags";
|
|
|
|
export const SelectionHeader = React.memo(() => {
|
|
const { colors } = useThemeColors();
|
|
const selectionMode = useSelectionStore((state) => state.selectionMode);
|
|
const selectedItemsList = useSelectionStore(
|
|
(state) => state.selectedItemsList
|
|
);
|
|
const setSelectionMode = useSelectionStore((state) => state.setSelectionMode);
|
|
const clearSelection = useSelectionStore((state) => state.clearSelection);
|
|
const currentScreen = useNavigationStore((state) => state.currentScreen);
|
|
const screen = currentScreen.name;
|
|
const insets = useGlobalSafeAreaInsets();
|
|
SearchService.prepareSearch?.();
|
|
const allItems = SearchService.getSearchInformation()?.get() || [];
|
|
const allSelected = allItems.length === selectedItemsList.length;
|
|
useEffect(() => {
|
|
if (selectionMode) {
|
|
tabBarRef.current?.lock();
|
|
} else {
|
|
tabBarRef.current?.unlock();
|
|
}
|
|
}, [selectionMode]);
|
|
|
|
const addToFavorite = async () => {
|
|
if (selectedItemsList.length > 0) {
|
|
selectedItemsList.forEach((item) => {
|
|
db.notes.note(item.id).favorite();
|
|
});
|
|
Navigation.queueRoutesForUpdate();
|
|
clearSelection();
|
|
}
|
|
};
|
|
|
|
const restoreItem = async () => {
|
|
if (selectedItemsList.length > 0) {
|
|
let noteIds = [];
|
|
selectedItemsList.forEach((item) => {
|
|
noteIds.push(item.id);
|
|
});
|
|
await db.trash.restore(...noteIds);
|
|
Navigation.queueRoutesForUpdate();
|
|
|
|
clearSelection();
|
|
ToastEvent.show({
|
|
heading: "Restore successful",
|
|
type: "success"
|
|
});
|
|
}
|
|
};
|
|
|
|
const deleteItem = async () => {
|
|
presentDialog({
|
|
title: `Delete ${selectedItemsList.length > 1 ? "items" : "item"}`,
|
|
paragraph: `Are you sure you want to delete ${
|
|
selectedItemsList.length > 1
|
|
? "these items permanently?"
|
|
: "this item permanently?"
|
|
}`,
|
|
positiveText: "Delete",
|
|
negativeText: "Cancel",
|
|
positivePress: async () => {
|
|
if (selectedItemsList.length > 0) {
|
|
let noteIds = [];
|
|
selectedItemsList.forEach((item) => {
|
|
noteIds.push(item.id);
|
|
});
|
|
await db.trash.delete(...noteIds);
|
|
Navigation.queueRoutesForUpdate();
|
|
clearSelection();
|
|
}
|
|
},
|
|
positiveType: "errorShade"
|
|
});
|
|
};
|
|
|
|
const onBackPress = useCallback(() => {
|
|
clearSelection();
|
|
return true;
|
|
}, [clearSelection]);
|
|
|
|
useEffect(() => {
|
|
if (selectionMode) {
|
|
BackHandler.addEventListener("hardwareBackPress", onBackPress);
|
|
} else {
|
|
BackHandler.removeEventListener("hardwareBackPress", onBackPress);
|
|
}
|
|
}, [onBackPress, selectionMode]);
|
|
|
|
return !selectionMode ? null : (
|
|
<View
|
|
style={{
|
|
width: "100%",
|
|
height: Platform.OS === "android" ? 50 + insets.top : 50,
|
|
paddingTop: Platform.OS === "android" ? insets.top : null,
|
|
backgroundColor: colors.primary.background,
|
|
justifyContent: "space-between",
|
|
alignItems: "center",
|
|
flexDirection: "row",
|
|
zIndex: 999,
|
|
paddingHorizontal: 12,
|
|
marginVertical: 10
|
|
}}
|
|
>
|
|
<View
|
|
style={{
|
|
flexDirection: "row",
|
|
justifyContent: "flex-start",
|
|
alignItems: "center",
|
|
borderRadius: 100
|
|
}}
|
|
>
|
|
<IconButton
|
|
customStyle={{
|
|
justifyContent: "center",
|
|
alignItems: "center",
|
|
height: 40,
|
|
width: 40,
|
|
borderRadius: 100,
|
|
marginRight: 10
|
|
}}
|
|
type="grayBg"
|
|
onPress={() => {
|
|
setSelectionMode(!selectionMode);
|
|
}}
|
|
size={SIZE.xl}
|
|
color={colors.primary.icon}
|
|
name="close"
|
|
/>
|
|
|
|
<View
|
|
style={{
|
|
backgroundColor: colors.secondary.background,
|
|
height: 40,
|
|
borderRadius: 100,
|
|
paddingHorizontal: 16,
|
|
justifyContent: "center",
|
|
flexDirection: "row",
|
|
alignItems: "center"
|
|
}}
|
|
>
|
|
<Heading size={SIZE.md} color={colors.primary.accent}>
|
|
{selectedItemsList.length}
|
|
</Heading>
|
|
</View>
|
|
</View>
|
|
<View
|
|
style={{
|
|
flexDirection: "row",
|
|
justifyContent: "flex-start",
|
|
alignItems: "center"
|
|
}}
|
|
>
|
|
<IconButton
|
|
onPress={async () => {
|
|
useSelectionStore
|
|
.getState()
|
|
.setAll(allSelected ? [] : [...allItems]);
|
|
}}
|
|
tooltipText="Select all"
|
|
tooltipPosition={4}
|
|
customStyle={{
|
|
marginLeft: 10
|
|
}}
|
|
color={colors.primary.paragraph}
|
|
name="select-all"
|
|
size={SIZE.xl}
|
|
/>
|
|
|
|
{screen === "Trash" ||
|
|
screen === "Notebooks" ||
|
|
screen === "Notebook" ||
|
|
screen === "Reminders" ? null : (
|
|
<>
|
|
<IconButton
|
|
onPress={async () => {
|
|
await sleep(100);
|
|
ManageTagsSheet.present(selectedItemsList);
|
|
}}
|
|
customStyle={{
|
|
marginLeft: 10
|
|
}}
|
|
color={colors.primary.icon}
|
|
tooltipText="Manage tags"
|
|
tooltipPosition={4}
|
|
name="pound"
|
|
size={SIZE.xl}
|
|
/>
|
|
<IconButton
|
|
onPress={async () => {
|
|
//setSelectionMode(false);
|
|
await sleep(100);
|
|
MoveNoteSheet.present();
|
|
}}
|
|
customStyle={{
|
|
marginLeft: 10
|
|
}}
|
|
tooltipText="Add to notebooks"
|
|
tooltipPosition={4}
|
|
color={colors.primary.paragraph}
|
|
name="plus"
|
|
size={SIZE.xl}
|
|
/>
|
|
|
|
<IconButton
|
|
onPress={async () => {
|
|
ExportNotesSheet.present(selectedItemsList);
|
|
}}
|
|
tooltipText="Export"
|
|
tooltipPosition={4}
|
|
customStyle={{
|
|
marginLeft: 10
|
|
}}
|
|
color={colors.primary.paragraph}
|
|
name="export"
|
|
size={SIZE.xl}
|
|
/>
|
|
</>
|
|
)}
|
|
|
|
{screen === "TopicNotes" || screen === "Notebook" ? (
|
|
<IconButton
|
|
onPress={async () => {
|
|
if (selectedItemsList.length > 0) {
|
|
const currentScreen =
|
|
useNavigationStore.getState().currentScreen;
|
|
|
|
if (screen === "Notebook") {
|
|
for (const item of selectedItemsList) {
|
|
await db.relations.unlink(
|
|
{ type: "notebook", id: currentScreen.id },
|
|
item
|
|
);
|
|
}
|
|
} else {
|
|
await db.notes.removeFromNotebook(
|
|
{
|
|
id: currentScreen.notebookId,
|
|
topic: currentScreen.id
|
|
},
|
|
...selectedItemsList.map((item) => item.id)
|
|
);
|
|
}
|
|
|
|
Navigation.queueRoutesForUpdate();
|
|
clearSelection();
|
|
}
|
|
}}
|
|
customStyle={{
|
|
marginLeft: 10
|
|
}}
|
|
tooltipText={`Remove from ${
|
|
screen === "Notebook" ? "notebook" : "topic"
|
|
}`}
|
|
tooltipPosition={4}
|
|
testID="select-minus"
|
|
color={colors.primary.paragraph}
|
|
name="minus"
|
|
size={SIZE.xl}
|
|
/>
|
|
) : null}
|
|
|
|
{screen === "Favorites" ? (
|
|
<IconButton
|
|
onPress={addToFavorite}
|
|
customStyle={{
|
|
marginLeft: 10
|
|
}}
|
|
tooltipText="Remove from favorites"
|
|
tooltipPosition={4}
|
|
color={colors.primary.paragraph}
|
|
name="star-off"
|
|
size={SIZE.xl}
|
|
/>
|
|
) : null}
|
|
|
|
{screen === "Trash" ? null : (
|
|
<IconButton
|
|
customStyle={{
|
|
marginLeft: 10
|
|
}}
|
|
onPress={async () => {
|
|
presentDialog({
|
|
title: `Delete ${
|
|
selectedItemsList.length > 1 ? "items" : "item"
|
|
}`,
|
|
paragraph: `Are you sure you want to delete ${
|
|
selectedItemsList.length > 1 ? "these items?" : "this item?"
|
|
}`,
|
|
positiveText: "Delete",
|
|
negativeText: "Cancel",
|
|
positivePress: () => {
|
|
deleteItems();
|
|
},
|
|
positiveType: "errorShade"
|
|
});
|
|
|
|
return;
|
|
}}
|
|
tooltipText="Move to trash"
|
|
tooltipPosition={1}
|
|
color={colors.primary.paragraph}
|
|
name="delete"
|
|
size={SIZE.xl}
|
|
/>
|
|
)}
|
|
|
|
{screen === "Trash" ? (
|
|
<>
|
|
<IconButton
|
|
customStyle={{
|
|
marginLeft: 10
|
|
}}
|
|
color={colors.primary.paragraph}
|
|
onPress={restoreItem}
|
|
name="delete-restore"
|
|
tooltipText="Restore"
|
|
tooltipPosition={4}
|
|
size={SIZE.xl - 3}
|
|
/>
|
|
|
|
<IconButton
|
|
customStyle={{
|
|
marginLeft: 10
|
|
}}
|
|
color={colors.primary.paragraph}
|
|
onPress={deleteItem}
|
|
tooltipText="Delete"
|
|
tooltipPosition={4}
|
|
name="delete"
|
|
size={SIZE.xl - 3}
|
|
/>
|
|
</>
|
|
) : null}
|
|
</View>
|
|
</View>
|
|
);
|
|
});
|
|
|
|
SelectionHeader.displayName = "SelectionHeader";
|
|
|
|
export default SelectionHeader;
|