expo local notifications how to set custom start and custom repeat - react-native

I'm creating an app in react native using expo where I need to set both a custom start time and a custom repeat interval time for notifications based on user input. For example, I need to start notifications in 15 days and then repeat every 27 days thereafter. I can figure out how to get it to trigger in 15 days, or repeat every 27 days, but not both together. I need it to work on Android and iOS.
import * as Notifications from "expo-notifications";
export default function notificationsConfig(repeatLength) {
const config = {
content: {
title: "Reminder",
body: "body.",
sound: false,
priority: Notifications.AndroidNotificationPriority.HIGH,
color: "blue",
},
trigger: {
/****Is there a way to set first notification date here?******/
seconds: 60 * 60 * 24 * repeatLength,
repeats: true,
},
};
return config;
}
Thank you!

Related

How to remove a specific notification forever using react-native-push-notification

I am currently using the react-native-push-notification library to schedule and receive notifications in my React Native app. I am able to cancel a scheduled notification using the cancelLocalNotification method, but this only cancels the notification for 24 hours. I want to find a way to remove a specific notification forever, so it will not be rescheduled.
I have tried using the following code to cancel a notification by its ID, but it only cancels it for 24 hours:
const onCancelNotification = async (id: string) => {
// Get a list of all scheduled notifications
PushNotification.getScheduledLocalNotifications((notifications) => {
// Iterate through the list of notifications
notifications.forEach((notification) => {
// Check if the notification is the one you want to cancel
if (notification.id.indexOf(id) === 0) {
// Cancel the notification
PushNotification.cancelLocalNotification(notification.id);
}
});
});
};
I would greatly appreciate any help or suggestions on how to achieve this.
This code snippet demonstrates a workaround for removing a specific scheduled local notification in React Native. The function onRemoveNotification takes in an id parameter, which is used to identify the specific notification that needs to be removed.
It's important to note that there is no direct method for removing a specific scheduled local notification in React Native. This code provides a workaround that can be used, but it's important to be aware that it relies on scheduling a notification with an earlier date and setting the repeatType to undefined.
Please note that this code is not a perfect solution and could have side effects on the app.
const onRemoveNotification = async (id: string) => {
// Get a list of all scheduled notifications
PushNotification.getScheduledLocalNotifications((notifications) => {
// Iterate through the list of notifications
notifications.forEach((notification) => {
// Check if the notification is the one you want to cancel
if (notification.data.notificationId?.indexOf(id) === 0) {
// Create a new date one day earlier than the current scheduled date
const earlyDate = moment(notification.date).add(-1, "day").toDate();
// remove the notification
// schedule the notification with an earlier date and repeat type undefined
// this will effectively "remove" the notification
// since it will not be displayed
PushNotification.localNotificationSchedule({
id: notification.id,
title: notification.title,
message: notification.message,
repeatType: undefined,
date: earlyDate,
});
// cancel the previous scheduled notification
PushNotification.cancelLocalNotification(notification.id);
}
});
});
};

Expo Notifications repeats after a specified date

Im trying to schedule a daily notification with expo notifications. I need to fire this notification from a specified date in the future. So it will be for example: schedule the notification on 20 days in the future and from there fire it daily until cancelled. How can't find anything in the documentation on how to do this. Does anyone have an idea?
You can set a starting date like this:
await Notifications.scheduleNotificationAsync({
content: {
title,
body,
sound: true,
vibrate: [0, 255, 255, 255],
},
trigger: {
date: "your-date"
},
});
Later on you can switch on repeats like this:
trigger: {
repeats: true //or false
},
I'm not sure what you mean by fire until cancelled. Should the user specifically cancel the notification or is som state variable changing? Either way, I think you can add repeats: true or false depending on any variable.
Hope this helps!

Local expo-notifications trigger Daily(SDK 39.0.0)

I'm trying to use the local notification and I am using the new notification module.
In the previous version, it had a repeat argument for Notifications.scheduleLocalNotificationAsync to work yearly or monthly.
In the new module, the repeated option was removed.
How can I be able to repeat my notification monthly or yearly?
This is the documentation in Expo: Scheduling Notifications
This is from the documentations, counting the yearly/monthly by seconds.
import * as Notifications from 'expo-notifications';
Notifications.scheduleNotificationAsync({
content: {
title: 'Remember to drink water!'
},
trigger: {
seconds: 60 * 60 * 24 * 365,
repeats: true
},
});

Hide/Snooze issues in YouTrack

I want to use YouTrack for Key-Account-Management.
There is one Epic and for each key account (customer) one sub-issue.
I want to talk to each key account roughly every 6 months.
Is there a way to hide or snooze an issue for some time.
The issue should be like resolved for some months, and then come back if the snooze time has expired.
How to do this with youtrack?
The issue should be like resolved for some months
It seems that one can simply resolve the issue to accomplish it.
The tricky part is to reopen them automatically in 6 months. The following workflow rule can reopen YouTrack issues by timer:
var entities = require('#jetbrains/youtrack-scripting-api/entities');
var workflow = require('#jetbrains/youtrack-scripting-api/workflow');
exports.rule = entities.Issue.onSchedule({
title: workflow.i18n('Reopen issues in 6 months'),
search: '#Resolved', // Narrow the search to specify which issues are affected
cron: '0 0 0 ? * * *', // Fires once a day
guard: function(ctx) {
// If an issue was in a resolved state for half a year already...
return Date.now() - ctx.issue.resolved < 15552000000;
},
action: function(ctx) {
// ... then reopen it
ctx.issue.State = ctx.State.Open;
},
requirements: {
State: {
type: entities.State.fieldType,
Open: {}
}
}
});

Rerender list in vue.js 2

I use moment.js to display how many time has passed from some event.
I have a list (rendered using vue.js)
event 3, 5 seconds ago
event 2, 1 minute ago
event 1, 5 minutes ago
The problem is: list is not updated frequently (new items are added, for example, every 2 minutes).
I want to update n (seconds|minutes) ago strings.
Should I do simple loop using setInterval?
for(let i = 0; i < this.list.length; i++) {
let item = this.list[i];
item.created_at_diff = moment(item.created_at).fromNow();
this.$set(this.list, i, item);
}
or there is a better approach?
Here is how I would do such a thing, tell me if I am wrong:
First, I would create a component that will make the timer:
let Timer = Vue.extend({
template: '#timer',
props: ['timestamp'],
data () {
return {
formatted: ''
}
},
methods: {
format () {
let self = this
this.formatted = moment().to(moment(this.timestamp,'X'))
// Uncomment this line to see that reactivity works
// this.formatted = moment().format('X')
setTimeout(() => {
self.format()
},500)
}
},
created () {
this.format()
}
})
The timer takes one property, a UNIX timestamp in seconds. The component contains one method called format() that will update the only data formatted of the component. The method is recursive and calls itself every 500ms (with the setTimeout()), you can make this number bigger if you want.
Here is a jsFiddle I made if you want to test it:
https://jsfiddle.net/54qhk08h/