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