Merge pull request #2259 from urbit/m/link-unreader

link: unread counters in sidebar
This commit is contained in:
Fang 2020-02-10 20:53:07 +01:00 committed by GitHub
commit 5eab689d0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 1 deletions

View File

@ -40,8 +40,11 @@
:: ::
:: scry-only paths: :: scry-only paths:
:: ::
:: (set url)
:: /seen//some-path the ones we've seen here
::
:: ? :: ?
:: /seen/wood-url/some-path have we seen this here (scry only) :: /seen/wood-url/some-path have we seen this here
:: ::
/+ *link, default-agent, verb, dbug /+ *link, default-agent, verb, dbug
:: ::
@ -151,6 +154,9 @@
:: ::
[%x %seen @ ^] [%x %seen @ ^]
``noun+!>((is-seen t.t.path)) ``noun+!>((is-seen t.t.path))
::
[%x %unseen *]
``noun+!>((get-unseen t.t.path))
== ==
:: ::
++ on-watch ++ on-watch
@ -372,6 +378,17 @@
%+ ~(put by *(map ^path submissions)) path %+ ~(put by *(map ^path submissions)) path
submissions:(~(gut by by-group) path *links) submissions:(~(gut by by-group) path *links)
:: ::
++ get-unseen
|= =path
^- (set url)
=/ =links
(~(gut by by-group) path *links)
%- ~(gas in *(set url))
%+ murn submissions.links
|= submission
?: (~(has in seen.links) url) ~
(some url)
::
++ is-seen ++ is-seen
|= =path |= =path
^- ? ^- ?

View File

@ -248,6 +248,16 @@
|= [=^path =submissions] |= [=^path =submissions]
^- [@t json] ^- [@t json]
:- (spat path) :- (spat path)
=; =json
:: add unseen count
::
?> ?=(%o -.json)
:- %o
%+ ~(put by p.json) 'unseenCount'
%- numb:enjs:format
%~ wyt in
%+ scry-for (set url)
[%unseen path]
%^ page-to-json p %^ page-to-json p
%+ get-paginated `p %+ get-paginated `p
submissions submissions

View File

@ -18,6 +18,9 @@ export class ChannelsSidebar extends Component {
let name = "Private" let name = "Private"
let selected = (props.selected === path); let selected = (props.selected === path);
let linkCount = !!props.links[path] ? props.links[path].totalItems : 0; let linkCount = !!props.links[path] ? props.links[path].totalItems : 0;
const unseenCount = !!props.links[path]
? props.links[path].unseenCount
: linkCount
return ( return (
<ChannelsItem <ChannelsItem
key={path} key={path}
@ -25,6 +28,7 @@ export class ChannelsSidebar extends Component {
members={props.paths[path]} members={props.paths[path]}
selected={selected} selected={selected}
linkCount={linkCount} linkCount={linkCount}
unseenCount={unseenCount}
name={name}/> name={name}/>
) )
}) })

View File

@ -11,6 +11,9 @@ export class ChannelsItem extends Component {
: "b--transparent"; : "b--transparent";
let memberCount = Object.keys(props.members).length; let memberCount = Object.keys(props.members).length;
const unseenCount = props.unseenCount > 0
? <span className="green2">{" " + props.unseenCount + " unread"}</span>
: null;
return ( return (
<Link to={"/~link" + props.link}> <Link to={"/~link" + props.link}>
@ -21,6 +24,7 @@ export class ChannelsItem extends Component {
</p> </p>
<p className="f9 pb1"> <p className="f9 pb1">
{props.linkCount + " link" + ((props.linkCount === 1) ? "" : "s")} {props.linkCount + " link" + ((props.linkCount === 1) ? "" : "s")}
{unseenCount}
</p> </p>
</div> </div>
</Link> </Link>

View File

@ -41,6 +41,7 @@ export class LinkUpdateReducer {
state.links[path].local[page] = false; state.links[path].local[page] = false;
state.links[path].totalPages = here.totalPages; state.links[path].totalPages = here.totalPages;
state.links[path].totalItems = here.totalItems; state.links[path].totalItems = here.totalItems;
state.links[path].unseenCount = here.unseenCount;
// write seen status to a separate structure, // write seen status to a separate structure,
// for easier modification later. // for easier modification later.
@ -74,6 +75,8 @@ export class LinkUpdateReducer {
state.links[path] = this._addNewItems( state.links[path] = this._addNewItems(
data.pages, state.links[path] data.pages, state.links[path]
); );
state.links[path].unseenCount =
state.links[path].unseenCount + data.pages.length;
} }
} }
@ -148,6 +151,10 @@ export class LinkUpdateReducer {
data.urls.map(url => { data.urls.map(url => {
seen[url] = true; seen[url] = true;
}); });
if (state.links[path]) {
state.links[path].unseenCount =
state.links[path].unseenCount - data.urls.length;
}
} }
} }