mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
add toast messag queuing
This commit is contained in:
@@ -272,7 +272,7 @@ export const ActionSheetComponent = ({
|
||||
name: 'Restore',
|
||||
icon: 'delete-restore',
|
||||
func: async () => {
|
||||
await db.trash.restore(note.id);
|
||||
console.log(await db.trash.restore(note.id),"RESULT");
|
||||
dispatch({type: ACTIONS.TRASH});
|
||||
localRefresh(note.type);
|
||||
ToastEvent.show(
|
||||
|
||||
@@ -35,28 +35,73 @@ export class Dialog extends Component {
|
||||
history.selectedItemsList.push(item);
|
||||
}
|
||||
|
||||
history.selectedItemsList.forEach(async i => {
|
||||
if (i.type === 'note') {
|
||||
await db.notes.delete(i.id);
|
||||
ToastEvent.show('Notes moved to trash', 'error');
|
||||
updateEvent({type: i.type});
|
||||
updateEvent({type: ACTIONS.PINNED});
|
||||
|
||||
for (var i = 0; i < history.selectedItemsList.length; i++) {
|
||||
let it = history.selectedItemsList[i];
|
||||
if (it.type === 'note') {
|
||||
await db.notes.delete(it.id);
|
||||
updateEvent({type: it.type});
|
||||
eSendEvent(eClearEditor);
|
||||
} else if (i.type === 'topic') {
|
||||
await db.notebooks.notebook(i.notebookId).topics.delete(i.title);
|
||||
|
||||
} else if (it.type === 'topic') {
|
||||
await db.notebooks.notebook(it.notebookId).topics.delete(it.title);
|
||||
eSendEvent(eOnNewTopicAdded);
|
||||
updateEvent({type: 'notebook'});
|
||||
|
||||
ToastEvent.show('Topics deleted', 'error');
|
||||
} else if (i.type === 'notebook') {
|
||||
await db.notebooks.delete(i.id);
|
||||
updateEvent({type: i.type});
|
||||
updateEvent({type: ACTIONS.PINNED});
|
||||
ToastEvent.show('Notebooks moved to trash', 'error');
|
||||
ToastEvent.show('Topics deleted', 'success');
|
||||
} else if (it.type === 'notebook') {
|
||||
await db.notebooks.delete(it.id);
|
||||
updateEvent({type: it.type});
|
||||
}
|
||||
});
|
||||
}
|
||||
updateEvent({type: ACTIONS.PINNED});
|
||||
|
||||
let message;
|
||||
let notes = history.selectedItemsList.filter((o) => o.type === 'note');
|
||||
let notebooks = history.selectedItemsList.filter(
|
||||
(o) => o.type === 'notebook',
|
||||
);
|
||||
let topics = history.selectedItemsList.filter(
|
||||
(o) => o.type === 'topic',
|
||||
);
|
||||
if (notes.length > 0 && notebooks.length === 0 && topics.length === 0) {
|
||||
let msgPart = notes.length > 1 ? ' notes' : ' note';
|
||||
message = notes.length + msgPart + ' moved to trash';
|
||||
} else if (
|
||||
notes.length === 0 &&
|
||||
notebooks.length > 0 &&
|
||||
topics.length === 0
|
||||
) {
|
||||
let msgPart = notebooks.length > 1 ? ' notebooks' : ' notebook';
|
||||
message = notebooks.length + msgPart + ' moved to trash';
|
||||
} else if (
|
||||
notes.length === 0 &&
|
||||
notebooks.length === 0 &&
|
||||
topics.length > 0
|
||||
) {
|
||||
let msgPart = topics.length > 1 ? ' topics' : ' topic';
|
||||
message = topics.length + msgPart + ' moved to trash';
|
||||
}
|
||||
let itemsCopy = [...history.selectedItemsList];
|
||||
if (history.selectedItemsList[0].type !== 'topic')
|
||||
ToastEvent.show(
|
||||
message,
|
||||
'success',
|
||||
'global',
|
||||
6000,
|
||||
async () => {
|
||||
console.log('COPY');
|
||||
let trash = db.trash;
|
||||
|
||||
for (var i = 0; i < itemsCopy.length; i++) {
|
||||
let it = itemsCopy[i];
|
||||
let trashItem = trash.all.find((item) => item.itemId === it.id);
|
||||
await db.trash.restore(trashItem.id);
|
||||
updateEvent({type: it.type});
|
||||
}
|
||||
updateEvent({type: ACTIONS.TRASH});
|
||||
updateEvent({type: ACTIONS.PINNED});
|
||||
ToastEvent.hide();
|
||||
},
|
||||
'Undo',
|
||||
);
|
||||
|
||||
updateEvent({type: ACTIONS.CLEAR_SELECTION});
|
||||
updateEvent({type: ACTIONS.SELECTION_MODE, enabled: false});
|
||||
@@ -70,7 +115,7 @@ export class Dialog extends Component {
|
||||
history.selectedItemsList.push(item);
|
||||
}
|
||||
let ids = [];
|
||||
history.selectedItemsList.forEach(item => ids.push(item.id));
|
||||
history.selectedItemsList.forEach((item) => ids.push(item.id));
|
||||
|
||||
await db.trash.delete(...ids);
|
||||
|
||||
@@ -236,18 +281,8 @@ export class Dialog extends Component {
|
||||
flexDirection: 'row',
|
||||
marginTop: 20,
|
||||
}}>
|
||||
<Button
|
||||
onPress={this._onClose}
|
||||
title={negativeText}
|
||||
grayed
|
||||
/>
|
||||
<Button
|
||||
onPress={this._onPress}
|
||||
title={positiveText}
|
||||
|
||||
/>
|
||||
|
||||
|
||||
<Button onPress={this._onClose} title={negativeText} grayed />
|
||||
<Button onPress={this._onPress} title={positiveText} />
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
|
||||
@@ -9,19 +9,24 @@ import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
||||
import {SIZE} from '../../common/common';
|
||||
const {spring, timing} = Animated;
|
||||
|
||||
const toastMessages = [];
|
||||
export const Toast = ({context = 'global'}) => {
|
||||
const [state, dispatch] = useTracked();
|
||||
const colors = state.colors;
|
||||
const [keyboard, setKeyboard] = useState(false);
|
||||
const [data, setData] = useState([]);
|
||||
const [data, setData] = useState({});
|
||||
const [toastStyle, setToastStyle] = useState({
|
||||
backgroundColor: colors.errorBg,
|
||||
color: colors.errorText,
|
||||
});
|
||||
|
||||
let toastTranslate = useValue(300);
|
||||
let toastOpacity = useValue(1);
|
||||
|
||||
const showToastFunc = (data) => {
|
||||
toastMessages.push(data);
|
||||
console.log(data, toastMessages.length);
|
||||
if (toastMessages?.length > 1) return;
|
||||
setData(data);
|
||||
if (data.type === 'success') {
|
||||
setToastStyle({
|
||||
@@ -42,28 +47,60 @@ export const Toast = ({context = 'global'}) => {
|
||||
}, 100);
|
||||
|
||||
setTimeout(() => {
|
||||
timing(toastTranslate, {
|
||||
toValue: 300,
|
||||
duration: 200,
|
||||
easing: Easing.inOut(Easing.ease),
|
||||
}).start();
|
||||
hideToastFunc();
|
||||
}, data.duration);
|
||||
};
|
||||
|
||||
const showNext = (data) => {
|
||||
setData(data);
|
||||
if (data.type === 'success') {
|
||||
setToastStyle({
|
||||
color: colors.successText,
|
||||
});
|
||||
} else {
|
||||
setToastStyle({
|
||||
color: colors.errorText,
|
||||
});
|
||||
}
|
||||
setTimeout(() => {
|
||||
hideToastFunc();
|
||||
}, toastMessages[0].duration);
|
||||
};
|
||||
|
||||
const hideToastFunc = (data) => {
|
||||
console.log(toastMessages.length);
|
||||
if (toastMessages.length > 1) {
|
||||
toastMessages.shift();
|
||||
|
||||
timing(toastOpacity, {
|
||||
toValue: 0,
|
||||
duration: 300,
|
||||
easing: Easing.in(Easing.ease),
|
||||
}).start(() => {
|
||||
showNext(toastMessages[0]);
|
||||
timing(toastOpacity, {
|
||||
toValue: 1,
|
||||
duration: 300,
|
||||
easing: Easing.in(Easing.ease),
|
||||
}).start();
|
||||
});
|
||||
} else {
|
||||
timing(toastTranslate, {
|
||||
toValue: 300,
|
||||
duration: 200,
|
||||
easing: Easing.inOut(Easing.ease),
|
||||
}).start();
|
||||
}).start(() => {
|
||||
setData({});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const _onKeyboardShow = () => {
|
||||
setKeyboard(true);
|
||||
//setKeyboard(true);
|
||||
};
|
||||
|
||||
const _onKeyboardHide = () => {
|
||||
setKeyboard(false);
|
||||
//setKeyboard(false);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
@@ -91,6 +128,7 @@ export const Toast = ({context = 'global'}) => {
|
||||
position: 'absolute',
|
||||
zIndex: 999,
|
||||
elevation: 15,
|
||||
opacity: toastOpacity,
|
||||
transform: [
|
||||
{
|
||||
translateY: toastTranslate,
|
||||
@@ -138,6 +176,9 @@ export const Toast = ({context = 'global'}) => {
|
||||
</View>
|
||||
|
||||
<Text
|
||||
onPress={() => {
|
||||
hideToastFunc();
|
||||
}}
|
||||
style={{
|
||||
color: 'white',
|
||||
backgroundColor: 'transparent',
|
||||
|
||||
@@ -80,7 +80,7 @@ export const h = Dimensions.get('window').height;
|
||||
export const ToastEvent = {
|
||||
show: (
|
||||
message,
|
||||
type,
|
||||
type = "error",
|
||||
context = 'global',
|
||||
duration = 6000,
|
||||
func = null,
|
||||
@@ -97,7 +97,7 @@ export const ToastEvent = {
|
||||
},
|
||||
hide: (
|
||||
message,
|
||||
type,
|
||||
type = "error",
|
||||
context = 'global',
|
||||
duration = 6000,
|
||||
func = null,
|
||||
|
||||
Reference in New Issue
Block a user