Skip to content

Commit

Permalink
global: implement the new theme engine (streetwriters#2196)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
ammarahm-ed and thecodrr authored Aug 1, 2023
1 parent ba72a92 commit 622294b
Show file tree
Hide file tree
Showing 439 changed files with 16,939 additions and 9,015 deletions.
2 changes: 2 additions & 0 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ const SCOPES = [
"editor",
"logger",
"theme",
"server",
"core",
"fs",
"ui",
"clipper",
"config",
"ci",
Expand Down
47 changes: 46 additions & 1 deletion apps/mobile/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ 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 {
THEME_COMPATIBILITY_VERSION,
useThemeEngineStore
} from "@notesnook/theme";
import React, { useEffect } from "react";
import { View } from "react-native";
import "react-native-gesture-handler";
Expand All @@ -29,7 +33,9 @@ import { ApplicationHolder } from "./navigation";
import Notifications from "./services/notifications";
import SettingsService from "./services/settings";
import { TipManager } from "./services/tip-manager";
import { useThemeStore } from "./stores/use-theme-store";
import { useUserStore } from "./stores/use-user-store";
import { themeTrpcClient } from "./screens/settings/theme-selector";

SettingsService.init();
SettingsService.checkOrientation();
Expand Down Expand Up @@ -87,4 +93,43 @@ const App = () => {
);
};

export default withErrorBoundry(App, "App");
export const withTheme = (Element) => {
return function AppWithThemeProvider() {
const [colorScheme, darkTheme, lightTheme] = useThemeStore((state) => [
state.colorScheme,
state.darkTheme,
state.lightTheme
]);

useEffect(() => {
const currentTheme = colorScheme === "dark" ? darkTheme : lightTheme;
if (!currentTheme) return;
themeTrpcClient.updateTheme
.query({
version: currentTheme.version,
compatibilityVersion: THEME_COMPATIBILITY_VERSION,
id: currentTheme.id
})
.then((theme) => {
if (theme) {
console.log(theme.version, "theme updated");
theme.colorScheme === "dark"
? useThemeStore.getState().setDarkTheme(theme)
: useThemeStore.getState().setLightTheme(theme);
}
})
.catch(console.log);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
useThemeEngineStore
.getState()
.setTheme(colorScheme === "dark" ? darkTheme : lightTheme);
}, [colorScheme, darkTheme, lightTheme]);

return <Element />;
};
};

export default withTheme(withErrorBoundry(App, "App"));
30 changes: 14 additions & 16 deletions apps/mobile/app/components/announcements/announcement.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ import React from "react";
import { FlatList, View } from "react-native";
import { useSelectionStore } from "../../stores/use-selection-store";
import { useMessageStore } from "../../stores/use-message-store";
import { useThemeStore } from "../../stores/use-theme-store";
import { useThemeColors } from "@notesnook/theme";
import { allowedOnPlatform, renderItem } from "./functions";

export const Announcement = ({ color }) => {
const colors = useThemeStore((state) => state.colors);
const { colors } = useThemeColors();
const announcements = useMessageStore((state) => state.announcements);
let announcement = announcements.length > 0 ? announcements[0] : null;
const selectionMode = useSelectionStore((state) => state.selectionMode);
return !announcement || selectionMode ? null : (
<View
style={{
backgroundColor: colors.bg,
backgroundColor: colors.primary.background,
width: "100%",
paddingHorizontal: 12,
paddingTop: 12,
Expand All @@ -44,28 +44,26 @@ export const Announcement = ({ color }) => {
width: "100%",
borderRadius: 10,
overflow: "hidden",
backgroundColor: colors.nav,
backgroundColor: colors.secondary.background,
paddingBottom: 12
}}
>
<View>
<FlatList
style={{
width: "100%",
marginTop: 12
}}
data={announcement?.body.filter((item) =>
allowedOnPlatform(item.platforms)
)}
renderItem={({ item, index }) =>
<View
style={{
width: "100%",
marginTop: 12
}}
>
{announcement?.body
.filter((item) => allowedOnPlatform(item.platforms))
.map((item, index) =>
renderItem({
item: item,
index: index,
color: colors[color],
inline: true
})
}
/>
)}
</View>
</View>
</View>
Expand Down
14 changes: 6 additions & 8 deletions apps/mobile/app/components/announcements/cta.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Linking, View } from "react-native";
//import SettingsBackupAndRestore from '../../screens/settings/backup-restore';
import { eSendEvent, presentSheet } from "../../services/event-manager";
import Sync from "../../services/sync";
import { useThemeStore } from "../../stores/use-theme-store";
import { useThemeColors } from "@notesnook/theme";
import { eCloseAnnouncementDialog, eCloseSheet } from "../../utils/events";
import { SIZE } from "../../utils/size";
import { sleep } from "../../utils/time";
Expand All @@ -33,7 +33,7 @@ import { Button } from "../ui/button";
import { allowedOnPlatform, getStyle } from "./functions";

export const Cta = ({ actions, style = {}, color, inline }) => {
const colors = useThemeStore((state) => state.colors);
const { colors } = useThemeColors();
let buttons =
actions.filter((item) => allowedOnPlatform(item.platforms)) || [];

Expand Down Expand Up @@ -92,8 +92,7 @@ export const Cta = ({ actions, style = {}, color, inline }) => {
style={{
height: 30,
alignSelf: "flex-start",
paddingHorizontal: 0,
marginTop: -6
paddingHorizontal: 0
}}
/>
))}
Expand All @@ -111,7 +110,6 @@ export const Cta = ({ actions, style = {}, color, inline }) => {
style={{
alignSelf: "flex-start",
paddingHorizontal: 0,
marginTop: -6,
marginLeft: 12
}}
textStyle={{
Expand All @@ -129,9 +127,9 @@ export const Cta = ({ actions, style = {}, color, inline }) => {
title={item.title}
fontSize={SIZE.md}
buttonType={{
color: color ? color : colors.accent,
text: colors.light,
selected: color ? color : colors.accent,
color: color ? color : colors.primary.accent,
text: colors.static.white,
selected: color ? color : colors.primary.accent,
opacity: 1
}}
onPress={() => onPress(item)}
Expand Down
6 changes: 3 additions & 3 deletions apps/mobile/app/components/announcements/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
eUnSubscribeEvent
} from "../../services/event-manager";
import { useMessageStore } from "../../stores/use-message-store";
import { useThemeStore } from "../../stores/use-theme-store";
import { useThemeColors } from "@notesnook/theme";
import {
eCloseAnnouncementDialog,
eOpenAnnouncementDialog
Expand All @@ -35,7 +35,7 @@ import { allowedOnPlatform, renderItem } from "./functions";
import { useCallback } from "react";

export const AnnouncementDialog = () => {
const colors = useThemeStore((state) => state.colors);
const { colors } = useThemeColors();
const [visible, setVisible] = useState(false);
const [info, setInfo] = useState(null);
const remove = useMessageStore((state) => state.remove);
Expand Down Expand Up @@ -73,7 +73,7 @@ export const AnnouncementDialog = () => {
<View
style={{
width: DDS.isTab ? 600 : "100%",
backgroundColor: colors.bg,
backgroundColor: colors.primary.background,
maxHeight: DDS.isTab ? "90%" : "100%",
borderRadius: DDS.isTab ? 10 : 0,
overflow: "hidden",
Expand Down
8 changes: 4 additions & 4 deletions apps/mobile/app/components/app-lock-overlay/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { db } from "../../common/database";
import { useAppState } from "../../hooks/use-app-state";
import BiometricService from "../../services/biometrics";
import { useSettingStore } from "../../stores/use-setting-store";
import { useThemeStore } from "../../stores/use-theme-store";
import { useThemeColors } from "@notesnook/theme";
import { useUserStore } from "../../stores/use-user-store";
import { NotesnookModule } from "../../utils/notesnook-module";
import { SIZE } from "../../utils/size";
Expand All @@ -36,7 +36,7 @@ import Heading from "../ui/typography/heading";
import Paragraph from "../ui/typography/paragraph";

const AppLockedOverlay = () => {
const colors = useThemeStore((state) => state.colors);
const { colors } = useThemeColors();
const user = useUserStore((state) => state.user);
const appLocked = useUserStore((state) => state.appLocked);
const lockApp = useUserStore((state) => state.lockApp);
Expand Down Expand Up @@ -134,10 +134,10 @@ const AppLockedOverlay = () => {
marginTop: user ? 0 : 50
}}
onPress={onUnlockAppRequested}
color={colors.border}
color={colors.primary.border}
/>
<Heading
color={colors.heading}
color={colors.primary.heading}
style={{
alignSelf: "center",
textAlign: "center"
Expand Down
22 changes: 11 additions & 11 deletions apps/mobile/app/components/attachments/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from "../../services/event-manager";
import PremiumService from "../../services/premium";
import { useAttachmentStore } from "../../stores/use-attachment-store";
import { useThemeStore } from "../../stores/use-theme-store";
import { useThemeColors } from "@notesnook/theme";
import { eCloseAttachmentDialog, eCloseSheet } from "../../utils/events";
import { SIZE } from "../../utils/size";
import { sleep } from "../../utils/time";
Expand All @@ -49,7 +49,7 @@ import Paragraph from "../ui/typography/paragraph";
import { formatBytes } from "@notesnook/common";

const Actions = ({ attachment, setAttachments, fwdRef }) => {
const colors = useThemeStore((state) => state.colors);
const { colors } = useThemeColors();
const contextId = attachment.metadata.hash;
const [filename, setFilename] = useState(attachment.metadata.filename);
const [currentProgress] = useAttachmentProgress(attachment);
Expand Down Expand Up @@ -194,7 +194,7 @@ const Actions = ({ attachment, setAttachments, fwdRef }) => {
<View
style={{
borderBottomWidth: 1,
borderBottomColor: colors.nav,
borderBottomColor: colors.secondary.background,
marginBottom: notes && notes.length > 0 ? 0 : 12
}}
>
Expand All @@ -219,7 +219,7 @@ const Actions = ({ attachment, setAttachments, fwdRef }) => {
style={{
marginRight: 10
}}
color={colors.icon}
color={colors.secondary.paragraph}
>
{attachment.metadata.type}
</Paragraph>
Expand All @@ -228,7 +228,7 @@ const Actions = ({ attachment, setAttachments, fwdRef }) => {
marginRight: 10
}}
size={SIZE.xs}
color={colors.icon}
color={colors.secondary.paragraph}
>
{formatBytes(attachment.length)}
</Paragraph>
Expand All @@ -239,7 +239,7 @@ const Actions = ({ attachment, setAttachments, fwdRef }) => {
marginRight: 10
}}
size={SIZE.xs}
color={colors.icon}
color={colors.secondary.paragraph}
>
{attachment.noteIds.length} note
{attachment.noteIds.length > 1 ? "s" : ""}
Expand All @@ -255,7 +255,7 @@ const Actions = ({ attachment, setAttachments, fwdRef }) => {
});
}}
size={SIZE.xs}
color={colors.icon}
color={colors.secondary.paragraph}
>
{attachment.metadata.hash}
</Paragraph>
Expand All @@ -268,7 +268,7 @@ const Actions = ({ attachment, setAttachments, fwdRef }) => {
<View
style={{
borderBottomWidth: 1,
borderBottomColor: colors.nav,
borderBottomColor: colors.secondary.background,
marginBottom: 12,
paddingVertical: 12
}}
Expand Down Expand Up @@ -322,10 +322,10 @@ const Actions = ({ attachment, setAttachments, fwdRef }) => {
key={item.name}
buttonType={{
text: item.on
? colors.accent
? colors.primary.accent
: item.name === "Delete" || item.name === "PermDelete"
? colors.errorText
: colors.pri
? colors.error.paragraph
: colors.primary.paragraph
}}
onPress={item.onPress}
title={item.name}
Expand Down
Loading

0 comments on commit 622294b

Please sign in to comment.