mirror of
https://github.com/urosran/cally.git
synced 2025-07-15 09:45:20 +00:00
Switch to day view when clicking on days in week and month view. Refresh tokens every 12 hrs
This commit is contained in:
@ -20,7 +20,7 @@ export const EventCalendar: React.FC<EventCalendarProps> = memo(({calendarHeight
|
|||||||
const {data: events} = useGetEvents();
|
const {data: events} = useGetEvents();
|
||||||
const {profileData} = useAuthContext()
|
const {profileData} = useAuthContext()
|
||||||
const [selectedDate, setSelectedDate] = useAtom(selectedDateAtom)
|
const [selectedDate, setSelectedDate] = useAtom(selectedDateAtom)
|
||||||
const mode = useAtomValue(modeAtom)
|
const [mode, setMode] = useAtom(modeAtom)
|
||||||
const setEditVisible = useSetAtom(editVisibleAtom)
|
const setEditVisible = useSetAtom(editVisibleAtom)
|
||||||
const setEventForEdit = useSetAtom(eventForEditAtom)
|
const setEventForEdit = useSetAtom(eventForEditAtom)
|
||||||
const setSelectedNewEndDate = useSetAtom(selectedNewEventDateAtom)
|
const setSelectedNewEndDate = useSetAtom(selectedNewEventDateAtom)
|
||||||
@ -41,7 +41,10 @@ export const EventCalendar: React.FC<EventCalendarProps> = memo(({calendarHeight
|
|||||||
height={calendarHeight}
|
height={calendarHeight}
|
||||||
activeDate={selectedDate}
|
activeDate={selectedDate}
|
||||||
date={selectedDate}
|
date={selectedDate}
|
||||||
onPressCell={setSelectedNewEndDate}
|
onPressCell={mode === "day" ? setSelectedNewEndDate: (date) => {
|
||||||
|
setSelectedDate(date)
|
||||||
|
setMode("day")
|
||||||
|
}}
|
||||||
headerContentStyle={mode === "day" ? styles.dayModeHeader : {}}
|
headerContentStyle={mode === "day" ? styles.dayModeHeader : {}}
|
||||||
onSwipeEnd={(date) => {
|
onSwipeEnd={(date) => {
|
||||||
setSelectedDate(date);
|
setSelectedDate(date);
|
||||||
|
@ -11,7 +11,6 @@ const db = admin.firestore();
|
|||||||
|
|
||||||
let expo = new Expo({accessToken: process.env.EXPO_ACCESS_TOKEN});
|
let expo = new Expo({accessToken: process.env.EXPO_ACCESS_TOKEN});
|
||||||
|
|
||||||
// Firestore trigger that listens for new events in the 'Events' collection
|
|
||||||
exports.sendNotificationOnEventCreation = functions.firestore
|
exports.sendNotificationOnEventCreation = functions.firestore
|
||||||
.document('Events/{eventId}')
|
.document('Events/{eventId}')
|
||||||
.onCreate(async (snapshot, context) => {
|
.onCreate(async (snapshot, context) => {
|
||||||
@ -193,6 +192,73 @@ exports.generateCustomToken = onRequest(async (request, response) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
exports.refreshTokens = functions.pubsub.schedule('every 12 hours').onRun(async (context) => {
|
||||||
|
console.log('Running token refresh job...');
|
||||||
|
|
||||||
|
const profilesSnapshot = await db.collection('Profiles').get();
|
||||||
|
|
||||||
|
profilesSnapshot.forEach(async (profileDoc) => {
|
||||||
|
const profileData = profileDoc.data();
|
||||||
|
|
||||||
|
if (profileData.googleToken) {
|
||||||
|
try {
|
||||||
|
const refreshedGoogleToken = await refreshGoogleToken(profileData.googleToken);
|
||||||
|
await profileDoc.ref.update({ googleToken: refreshedGoogleToken });
|
||||||
|
console.log(`Google token updated for user ${profileDoc.id}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error refreshing Google token for user ${profileDoc.id}:`, error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (profileData.microsoftToken) {
|
||||||
|
try {
|
||||||
|
const refreshedMicrosoftToken = await refreshMicrosoftToken(profileData.microsoftToken);
|
||||||
|
await profileDoc.ref.update({ microsoftToken: refreshedMicrosoftToken });
|
||||||
|
console.log(`Microsoft token updated for user ${profileDoc.id}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error refreshing Microsoft token for user ${profileDoc.id}:`, error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (profileData.appleToken) {
|
||||||
|
try {
|
||||||
|
const refreshedAppleToken = await refreshAppleToken(profileData.appleToken);
|
||||||
|
await profileDoc.ref.update({ appleToken: refreshedAppleToken });
|
||||||
|
console.log(`Apple token updated for user ${profileDoc.id}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error refreshing Apple token for user ${profileDoc.id}:`, error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Function to refresh Google token
|
||||||
|
async function refreshGoogleToken(token) {
|
||||||
|
// Assuming you use OAuth2 token refresh flow
|
||||||
|
const response = await axios.post('https://oauth2.googleapis.com/token', {
|
||||||
|
grant_type: 'refresh_token',
|
||||||
|
refresh_token: token, // Add refresh token stored previously
|
||||||
|
client_id: 'YOUR_GOOGLE_CLIENT_ID',
|
||||||
|
client_secret: 'YOUR_GOOGLE_CLIENT_SECRET',
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.data.access_token; // Return new access token
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshMicrosoftToken(token) {
|
||||||
|
const response = await axios.post('https://login.microsoftonline.com/common/oauth2/v2.0/token', {
|
||||||
|
grant_type: 'refresh_token',
|
||||||
|
refresh_token: token, // Add refresh token stored previously
|
||||||
|
client_id: 'YOUR_MICROSOFT_CLIENT_ID',
|
||||||
|
client_secret: 'YOUR_MICROSOFT_CLIENT_SECRET',
|
||||||
|
scope: 'https://graph.microsoft.com/Calendars.ReadWrite offline_access',
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.data.access_token; // Return new access token
|
||||||
|
}
|
||||||
|
|
||||||
async function getPushTokensForEvent() {
|
async function getPushTokensForEvent() {
|
||||||
const usersRef = db.collection('Profiles');
|
const usersRef = db.collection('Profiles');
|
||||||
const snapshot = await usersRef.get();
|
const snapshot = await usersRef.get();
|
||||||
@ -223,4 +289,4 @@ async function getPushTokensForFamilyExcludingCreator(familyId, creatorId) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return pushTokens;
|
return pushTokens;
|
||||||
}
|
}
|
@ -108,6 +108,7 @@
|
|||||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
||||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
||||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
||||||
</array>
|
</array>
|
||||||
<key>UILaunchStoryboardName</key>
|
<key>UILaunchStoryboardName</key>
|
||||||
<string>SplashScreen</string>
|
<string>SplashScreen</string>
|
||||||
|
Reference in New Issue
Block a user