mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 22:49:45 +01:00
fix state issues
This commit is contained in:
@@ -13,22 +13,25 @@ import { PressableButton } from '../ui/pressable';
|
||||
import Heading from '../ui/typography/heading';
|
||||
import Paragraph from '../ui/typography/paragraph';
|
||||
|
||||
export const ColorSection = () => {
|
||||
const colorNotes = useMenuStore(state => state.colorNotes);
|
||||
const loading = useNoteStore(state => state.loading);
|
||||
const setColorNotes = useMenuStore(state => state.setColorNotes);
|
||||
export const ColorSection = React.memo(
|
||||
() => {
|
||||
const colorNotes = useMenuStore(state => state.colorNotes);
|
||||
const loading = useNoteStore(state => state.loading);
|
||||
const setColorNotes = useMenuStore(state => state.setColorNotes);
|
||||
|
||||
useEffect(() => {
|
||||
if (!loading) {
|
||||
setColorNotes();
|
||||
}
|
||||
}, [loading]);
|
||||
useEffect(() => {
|
||||
if (!loading) {
|
||||
setColorNotes();
|
||||
}
|
||||
}, [loading]);
|
||||
|
||||
return colorNotes.map((item, index) => {
|
||||
let alias = db.colors.alias(item.id);
|
||||
return <ColorItem key={item.id} alias={alias} item={item} index={index} />;
|
||||
});
|
||||
};
|
||||
return colorNotes.map((item, index) => {
|
||||
let alias = db.colors.alias(item.id);
|
||||
return <ColorItem key={item.id} alias={alias} item={item} index={index} />;
|
||||
});
|
||||
},
|
||||
() => true
|
||||
);
|
||||
|
||||
const ColorItem = React.memo(
|
||||
({ item, index, alias }) => {
|
||||
|
||||
@@ -20,7 +20,8 @@ export const SideMenu = React.memo(
|
||||
const colors = useThemeStore(state => state.colors);
|
||||
const deviceMode = useSettingStore(state => state.deviceMode);
|
||||
const insets = useSafeAreaInsets();
|
||||
const user = useUserStore(state => state.user);
|
||||
const subscriptionType = useUserStore(state => state.user?.subscription?.type);
|
||||
console.log(subscriptionType);
|
||||
const noTextMode = false;
|
||||
|
||||
const BottomItemsList = [
|
||||
@@ -98,9 +99,8 @@ export const SideMenu = React.memo(
|
||||
paddingHorizontal: 12
|
||||
}}
|
||||
>
|
||||
{!user ||
|
||||
user?.subscription?.type === SUBSCRIPTION_STATUS.TRIAL ||
|
||||
user?.subscription?.type === SUBSCRIPTION_STATUS.BASIC ? (
|
||||
{subscriptionType === SUBSCRIPTION_STATUS.TRIAL ||
|
||||
subscriptionType === SUBSCRIPTION_STATUS.BASIC ? (
|
||||
<MenuItem testID={pro.name} key={pro.name} item={pro} index={0} ignore={true} />
|
||||
) : null}
|
||||
|
||||
|
||||
@@ -17,94 +17,96 @@ import SheetWrapper from '../ui/sheet';
|
||||
import Heading from '../ui/typography/heading';
|
||||
import Paragraph from '../ui/typography/paragraph';
|
||||
|
||||
export const TagsSection = () => {
|
||||
const menuPins = useMenuStore(state => state.menuPins);
|
||||
const loading = useNoteStore(state => state.loading);
|
||||
const setMenuPins = useMenuStore(state => state.setMenuPins);
|
||||
export const TagsSection = React.memo(
|
||||
() => {
|
||||
const menuPins = useMenuStore(state => state.menuPins);
|
||||
const loading = useNoteStore(state => state.loading);
|
||||
const setMenuPins = useMenuStore(state => state.setMenuPins);
|
||||
|
||||
useEffect(() => {
|
||||
if (!loading) {
|
||||
setMenuPins();
|
||||
}
|
||||
}, [loading]);
|
||||
useEffect(() => {
|
||||
if (!loading) {
|
||||
setMenuPins();
|
||||
}
|
||||
}, [loading]);
|
||||
|
||||
const onPress = item => {
|
||||
let params = {};
|
||||
if (item.type === 'notebook') {
|
||||
params = {
|
||||
notebook: item,
|
||||
title: item.title,
|
||||
menu: true
|
||||
};
|
||||
eSendEvent(eOnNewTopicAdded, params);
|
||||
Navigation.navigate('Notebook', params, {
|
||||
heading: item.title,
|
||||
id: item.id,
|
||||
type: item.type
|
||||
});
|
||||
} else if (item.type === 'tag') {
|
||||
params = {
|
||||
...item,
|
||||
type: 'tag',
|
||||
menu: true,
|
||||
get: 'tagged'
|
||||
};
|
||||
eSendEvent(refreshNotesPage, params);
|
||||
Navigation.navigate('NotesPage', params, {
|
||||
heading: '#' + db.tags.alias(item.id),
|
||||
id: item.id,
|
||||
type: item.type
|
||||
});
|
||||
} else {
|
||||
params = { ...item, menu: true, get: 'topics' };
|
||||
eSendEvent(refreshNotesPage, params);
|
||||
Navigation.navigate('NotesPage', params, {
|
||||
heading: item.title,
|
||||
id: item.id,
|
||||
type: item.type
|
||||
});
|
||||
}
|
||||
Navigation.closeDrawer();
|
||||
};
|
||||
const onPress = item => {
|
||||
let params = {};
|
||||
if (item.type === 'notebook') {
|
||||
params = {
|
||||
notebook: item,
|
||||
title: item.title,
|
||||
menu: true
|
||||
};
|
||||
eSendEvent(eOnNewTopicAdded, params);
|
||||
Navigation.navigate('Notebook', params, {
|
||||
heading: item.title,
|
||||
id: item.id,
|
||||
type: item.type
|
||||
});
|
||||
} else if (item.type === 'tag') {
|
||||
params = {
|
||||
...item,
|
||||
type: 'tag',
|
||||
menu: true,
|
||||
get: 'tagged'
|
||||
};
|
||||
eSendEvent(refreshNotesPage, params);
|
||||
Navigation.navigate('NotesPage', params, {
|
||||
heading: '#' + db.tags.alias(item.id),
|
||||
id: item.id,
|
||||
type: item.type
|
||||
});
|
||||
} else {
|
||||
params = { ...item, menu: true, get: 'topics' };
|
||||
eSendEvent(refreshNotesPage, params);
|
||||
Navigation.navigate('NotesPage', params, {
|
||||
heading: item.title,
|
||||
id: item.id,
|
||||
type: item.type
|
||||
});
|
||||
}
|
||||
Navigation.closeDrawer();
|
||||
};
|
||||
const renderItem = ({ item, index }) => {
|
||||
let alias = item ? (item.type === 'tag' ? db.tags.alias(item.title) : item.title) : null;
|
||||
return <PinItem item={item} index={index} alias={alias} onPress={onPress} />;
|
||||
};
|
||||
|
||||
const renderItem = ({ item, index }) => {
|
||||
let alias = item.type === 'tag' ? db.tags.alias(item.title) : item.title;
|
||||
return <PinItem item={item} index={index} alias={alias} onPress={onPress} />;
|
||||
};
|
||||
|
||||
return (
|
||||
<View
|
||||
style={{
|
||||
flexGrow: 1
|
||||
}}
|
||||
>
|
||||
<FlatList
|
||||
data={menuPins}
|
||||
return (
|
||||
<View
|
||||
style={{
|
||||
flexGrow: 1
|
||||
}}
|
||||
ListEmptyComponent={
|
||||
<Notice
|
||||
size="small"
|
||||
type="information"
|
||||
text="Add shortcuts for notebooks, topics and tags here."
|
||||
/>
|
||||
}
|
||||
contentContainerStyle={{
|
||||
flexGrow: 1
|
||||
}}
|
||||
keyExtractor={(item, index) => item.id}
|
||||
renderItem={renderItem}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
>
|
||||
<FlatList
|
||||
data={menuPins}
|
||||
style={{
|
||||
flexGrow: 1
|
||||
}}
|
||||
ListEmptyComponent={
|
||||
<Notice
|
||||
size="small"
|
||||
type="information"
|
||||
text="Add shortcuts for notebooks, topics and tags here."
|
||||
/>
|
||||
}
|
||||
contentContainerStyle={{
|
||||
flexGrow: 1
|
||||
}}
|
||||
keyExtractor={(item, index) => item.id}
|
||||
renderItem={renderItem}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
},
|
||||
() => true
|
||||
);
|
||||
|
||||
export const PinItem = React.memo(
|
||||
({ item, index, onPress, placeholder, alias }) => {
|
||||
const colors = useThemeStore(state => state.colors);
|
||||
const setMenuPins = useMenuStore(state => state.setMenuPins);
|
||||
alias = item.type === 'tag' ? db.tags.alias(item.title) : item.title;
|
||||
alias = !item ? '' : item.type === 'tag' ? db.tags.alias(item.title) : item.title;
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [headerTextState, setHeaderTextState] = useState(null);
|
||||
const color = headerTextState?.id === item.id ? colors.accent : colors.pri;
|
||||
@@ -238,6 +240,7 @@ export const PinItem = React.memo(
|
||||
);
|
||||
},
|
||||
(prev, next) => {
|
||||
if (!next.item) return false;
|
||||
if (prev.alias !== next.alias) return false;
|
||||
if (prev.item?.dateModified !== next.item?.dateModified) return false;
|
||||
if (prev.item?.id !== next.item?.id) return false;
|
||||
|
||||
@@ -299,7 +299,6 @@ export const useActions = ({ close = () => {}, item }) => {
|
||||
try {
|
||||
if (isPinnedToMenu) {
|
||||
await db.settings.unpin(item.id);
|
||||
return;
|
||||
} else {
|
||||
if (item.type === 'topic') {
|
||||
await db.settings.pin(item.type, {
|
||||
|
||||
@@ -165,6 +165,7 @@ export const useAppEvents = () => {
|
||||
};
|
||||
|
||||
const onSyncComplete = async () => {
|
||||
console.log('sync complete');
|
||||
initialize();
|
||||
setLastSynced(await db.lastSynced());
|
||||
if (getNote()) {
|
||||
@@ -219,6 +220,7 @@ export const useAppEvents = () => {
|
||||
};
|
||||
|
||||
const onRequestPartialSync = async (full, force) => {
|
||||
console.log('auto sync request', full, force);
|
||||
try {
|
||||
if (full || force) {
|
||||
Sync.run('global', force, full);
|
||||
|
||||
Reference in New Issue
Block a user