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

Show badge with unread counter #90

Open
4 of 8 tasks
brunolemos opened this issue Jan 8, 2019 · 17 comments
Open
4 of 8 tasks

Show badge with unread counter #90

brunolemos opened this issue Jan 8, 2019 · 17 comments

Comments

@brunolemos
Copy link
Member

brunolemos commented Jan 8, 2019

  • Show an "unread dot" on sidebar items
  • Show a badge counter on app icon:
    • Web
    • Desktop
    • iOS
    • Android
  • Only enable for the columns the user specify

Help wanted

@brunolemos brunolemos mentioned this issue Jan 9, 2019
5 tasks
@brunolemos brunolemos changed the title Show badge with unread counter (opt-in) Show badge with unread counter Jan 9, 2019
@panva
Copy link

panva commented Mar 6, 2019

@brunolemos how about Menubar mode badge in the status bar?

@dkniffin
Copy link
Contributor

Menubar badge would be 💯. I've been using Gitify for a long time, and it changes the color when there's unread notifications, which works great. But knowing the number too somehow would be icing on that cake.

@dkniffin
Copy link
Contributor

I might actually take a stab at implementing that. I'm familiar with the react-native-web architecture, but not the specifics of this project. Is this the right place for that change?

Also, for the number, the only way I can think to do it is to have different images for each number. Maybe created dynamically as discussed here: electron/electron#7322

@brunolemos
Copy link
Member Author

brunolemos commented Jun 25, 2019

@dkniffin yes that would be the file!

I think the hardest part will be that each column needs to have a config to enable or disable the badge (and I haven't created a UI for that or thought about config object structure yet); but we can think of a simpler solution to start.

I recently created a method called getItemsFilterMetadata that returns the number of unread items for a specific column and that was a requirement for the badge feature, so it will come handy.

const filteredItemsMetadata = getItemsFilterMetadata(
column.type,
getFilteredItems(
column.type,
allItems,
{ ...column.filters, unread: undefined },
getFilteredItemsOptions,
),
)

unread: filteredItemsMetadata.inbox[inbox].unread,

The code above shows the number 49 at the screenshot below:

image

Also needs to think where is the best place to put a watcher for these unread numbers. Probably a react Context. And then, send the info to electron using the window.ipc.send method.

@jletey
Copy link
Contributor

jletey commented Jun 26, 2019

@dkniffin are you going to just work on the icon badge counter? if so, I can have a go at the "unread dot" on sidebar items (kind of like Slack and Discord)

@dkniffin
Copy link
Contributor

@johnletey Yeah, if I do anything on here, it would be the menubar indicator

@jletey
Copy link
Contributor

jletey commented Jun 26, 2019

@dkniffin Wonderful ... I will get started on the "unread dot" feature now!

@dkniffin
Copy link
Contributor

@brunolemos I'm trying to get the menubar/tray indicator working. I know how to render it, but I'm having a hard time figuring out how to get the data needed to determine which state to render it in. You mentioned getItemsFilterMetadata, but I'm not sure how to use that in the Tray.ts file, since I need access to a column, but I don't know which column is being displayed. Thoughts?

@brunolemos
Copy link
Member Author

brunolemos commented Jun 30, 2019

@dkniffin the tray.ts file is the last step, everything else will happen inside the components package.

Check the file Sidebar.tsx, it is a mess but it has everything you need there. It lists all the columns and show an unread indicator.

I think we need a React Context, e.g. UnreadWatcherContext.tsx, that will be responsible to check the unread indicator for all columns. If there are columns with unread items, let’s sum the number of items and communicate it to Electron (which is running on a different thread).

To send messages to Electron, first check that it is an electron app (if (Platform.isElectron) {) and send the event (e.g. window.ipc.send(‘unread-counter’, numberOfUnreadItems)).

You need to listen to this unread-counter event on Electron (file desktop/src/index.ts), with a app.on(‘unread-counter’, … event listener). And then change the menubar icon badge (tray.yourMethodHere(counter)).

@dkniffin
Copy link
Contributor

Ok, thanks. That makes sense. I'll give that a shot

@brunolemos
Copy link
Member Author

You can use this to get all the columns:

const columns = useReduxState(selectors.columnsArrSelector)

And then for each column you do something like this to get the unread count for each one:

const { allItems } = useColumnData(column.id, getFilteredItemsOptions)
const filteredItemsMetadata = getItemsFilterMetadata(
column.type,
getFilteredItems(
column.type,
allItems,
{ ...column.filters, unread: undefined },
getFilteredItemsOptions,
),
)
const inbox =
column.type === 'notifications' &&
column.filters &&
column.filters.notifications &&
column.filters.notifications.participating
? 'participating'
: 'all'
const isUnread =
filteredItemsMetadata.inbox[inbox].unread > 0 ? true : false

@dkniffin
Copy link
Contributor

@brunolemos These context objects are unfamiliar to me. Are these the same as React Contexts or is this a different thing?

@brunolemos
Copy link
Member Author

brunolemos commented Jun 30, 2019

@dkniffin yes, normal React Context, like this: https://github.com/devhubapp/devhub/blob/master/packages/components/src/components/context/ColumnWidthContext.tsx

That is initiated at the App.tsx file: https://github.com/devhubapp/devhub/blob/master/packages/components/src/components/App.tsx

@dkniffin
Copy link
Contributor

@brunolemos Sorry I keep pestering you with questions about this. I think I've got the context set up correctly, and I understand how to pass the event over to electron, but the piece I'm missing is where to actually do that passing. Does that belong in MainScreen.tsx or somewhere else?

@brunolemos
Copy link
Member Author

Hm you can do it directly inside the context provider for now, or create a new file (e.g. AppIconBadge.tsx) and include it at the MainScreen render (<AppIconBadge />). And then inside this file read the context value (that should return the number of unread items) and update the app icon accordingly.

brunolemos added a commit that referenced this issue Jul 2, 2019
While we dont have an option to specify which columns we wanna enable.

#90
brunolemos added a commit that referenced this issue Jul 3, 2019
brunolemos added a commit that referenced this issue Jul 4, 2019
@brunolemos
Copy link
Member Author

brunolemos commented Jul 11, 2019

This is now available on v0.93.0! For web and desktop.

@brunolemos
Copy link
Member Author

brunolemos commented Jul 11, 2019

To show an unread badge on mobile there are two possible ways:

  1. Run a script on app background every X minutes (has limitations: if app gets closed it will stop updating, minimum 15 minute interval to update, etc)
  2. Move this responsibility to the server (probably would not scale well, imagine the server having to do thousands of github API requests per minute)

N2 would provide a better UX but not sure if it's feasible, github would block the server for spamming/ddos. Help wanted on N1 for now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants