Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reminders v1 #93

Merged
merged 7 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
POC tested; native browser notifications implemented;
Signed-off-by: Sahil Shubham <[email protected]>
  • Loading branch information
sahil-shubham committed Jun 22, 2022
commit 4dd44917511be5aecea97ad0c33344ff98123dc9
9 changes: 8 additions & 1 deletion apps/extension/src/Hooks/useRaju.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import {
Contents,
idxKey,
ILink,
mog,
NodeEditorContent,
NodeMetadata,
Reminder,
Snippet,
UserDetails,
WorkspaceDetails
Expand All @@ -14,6 +16,7 @@ import { AsyncMethodReturns, Methods } from 'penpal'
import toast from 'react-hot-toast'
import { useContentStore } from '../Stores/useContentStore'
import useDataStore from '../Stores/useDataStore'
import { useReminderStore } from '../Stores/useReminderStore'
import { useSnippetStore } from '../Stores/useSnippetStore'
import { useAuthStore } from './useAuth'
import useInternalAuthStore from './useAuthStore'
Expand All @@ -38,6 +41,7 @@ export default function useRaju() {
const initContents = useContentStore((store) => store.initContents)
const setIlinks = useDataStore((store) => store.setIlinks)
const initSnippets = useSnippetStore((store) => store.initSnippets)
const setReminders = useReminderStore((store) => store.setReminders)

const methods: Methods = {
init(
Expand All @@ -47,14 +51,17 @@ export default function useRaju() {
authAWS: any,
snippets: Snippet[],
contents: Contents,
ilinks: any[]
ilinks: any[],
reminders: Reminder[]
) {
setAuthenticated(userDetails, workspaceDetails)
setTheme(theme)
setInternalAuthStore(authAWS)
initSnippets(snippets)
setIlinks(ilinks)
initContents(contents)
setReminders(reminders)
mog('reminders raju', { reminders })
},
success(message: string) {
toast.success(message)
Expand Down
3 changes: 3 additions & 0 deletions apps/extension/src/Hooks/useReminders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ export const useReminders = () => {
// independent: true,
// attachment: reminderGroups
// })
chrome.runtime.sendMessage({ type: 'SHOW_REMINDER', attachment: reminderGroups }, (response) => {
console.log('response post SHOW_REMINDER', response)
})
}, time - now.getTime())
toArmRems.forEach((r) => addArmReminder({ reminderId: r.id, timeoutId: id }))
}
Expand Down
14 changes: 14 additions & 0 deletions apps/extension/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
return true
}

case 'SHOW_REMINDER': {
console.log('reminderGroups', request.attachment)
const firstReminder = request.attachment[0]?.reminders[0]
chrome.notifications.create(firstReminder.id, {
message: firstReminder.description,
title: firstReminder.title,
type: 'basic',
iconUrl: './Assets/icon48x48.png',
priority: 2,
requireInteraction: true
})
return true
}

default: {
return true
}
Expand Down
3 changes: 2 additions & 1 deletion apps/extension/src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"storage",
"tabs",
"activeTab",
"search"
"search",
"notifications"
],
"web_accessible_resources": [
{
Expand Down
4 changes: 3 additions & 1 deletion apps/webapp/src/Components/Chotu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { initSearchIndex, searchWorker } from '../Workers/controller'
import { useContentStore } from '../Stores/useContentStore'
import { useDataStore } from '../Stores/useDataStore'
import { useSnippetStore } from '../Stores/useSnippetStore'
import { useReminderStore } from '../Stores/useReminderStore'

export default function Chotu() {
const [parent, setParent] = useState<AsyncMethodReturns<any>>(null)
Expand All @@ -20,6 +21,7 @@ export default function Chotu() {
const theme = useThemeStore((state) => state.theme)
const authAWS = JSON.parse(localStorage.getItem('auth-aws')).state
const snippets = useSnippetStore((store) => store.snippets)
const reminders = useReminderStore((store) => store.reminders)

const { ilinks, archive, addILink } = useDataStore()
const { contents, setContent } = useContentStore()
Expand Down Expand Up @@ -56,7 +58,7 @@ export default function Chotu() {
useEffect(() => {
connection.promise
.then((parent: any) => {
parent.init(userDetails, workspaceDetails, theme, authAWS, snippets, contents, ilinks)
parent.init(userDetails, workspaceDetails, theme, authAWS, snippets, contents, ilinks, reminders)
// parent.success('Hi')
})
.catch((error) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/Components/Reminders/Reminders.style.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mix, transparentize } from 'polished'
import styled, { createGlobalStyle, css } from 'styled-components'
import { ReminderStatus, REMINDERS_DIMENSIONS } from '../../Hooks/useReminders'
import { Title, Button } from '@mexit/shared'
import { REMINDERS_DIMENSIONS, ReminderStatus } from '@mexit/core'

export const RemindersWrapper = styled.div`
margin: ${({ theme }) => theme.spacing.medium} 0;
Expand Down
2 changes: 2 additions & 0 deletions apps/webapp/src/Stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useEditorStore } from './useEditorStore'
import { useSnippetStore } from './useSnippetStore'
import { useTodoStore } from './useTodoStore'
import usePortalStore from './usePortalStore'
import { useReminderStore } from './useReminderStore'

if (IS_DEV) {
console.log('Zustand Devtools Initialize')
Expand Down Expand Up @@ -44,6 +45,7 @@ if ('BroadcastChannel' in globalThis /* || isSupported() */) {
share('contents', useContentStore)
// share('authenticated', useAuthStore)
// share('snippets', useSnippetStore)
// share('reminders', useReminderStore)
}

export default {}