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

client: Mark entry as read when opening external link #1470

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 2 additions & 7 deletions client/js/templates/EntriesPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,13 @@ function reloadList({
* @param {number} selected
*/
function openSelectedArticle(selected) {
const link = document.querySelector(`.entry[data-entry-id="${selected}"] .entry-datetime`);
const link = document.querySelector(`.entry[data-entry-id="${selected}"] .entry-newwindow`);
if (selfoss.config.openInBackgroundTab) {
// In Chromium, this will just cause the tab to open in the foreground.
// Appears to be disallowed by the pop-under prevention:
// https://crbug.com/431335
// https://crbug.com/487919
const event = new MouseEvent(
'click',
{
ctrlKey: true,
}
);
const event = new MouseEvent('click', { ctrlKey: true, bubbles: true});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why bubble?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The event handler for marking the entry as read doesn't fire otherwise. I'm not 100% sure why, because the event is dispatched on the element we registered the handler to, but without bubbling only the link opens but the handler doesn't run. Anyway, .click() and actual clicks bubble by default too, so we just make it behave the same.

link.dispatchEvent(event);
} else {
// open item in new window
Expand Down
23 changes: 15 additions & 8 deletions client/js/templates/Item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ function setupLightbox({
}));
}

function stopPropagation(event) {
event.stopPropagation();
}

function lazyLoadImages(content) {
content.querySelectorAll('img').forEach((img) => {
img.setAttribute('src', img.getAttribute('data-selfoss-src'));
Expand Down Expand Up @@ -257,6 +253,8 @@ export default function Item({ currentTime, item, selected, expanded, setNavExpa
[currentTime, item.datetime]
);

const canWrite = useAllowedToWrite();

const previouslyExpanded = usePreviousImmediate(expanded);
const configuration = useContext(ConfigurationContext);

Expand Down Expand Up @@ -387,6 +385,17 @@ export default function Item({ currentTime, item, selected, expanded, setNavExpa
[item]
);

const externalLinkOnClick = useCallback(
(event) => {
event.stopPropagation();

if (canWrite) {
selfoss.entriesPage.markEntryRead(item.id, true);
}
},
[canWrite, item.id]
);

const loadImagesOnClick = useCallback(
(event) => loadImages({ event, setImagesLoaded, contentBlock }),
[]
Expand All @@ -411,8 +420,6 @@ export default function Item({ currentTime, item, selected, expanded, setNavExpa
[item.source]
);

const canWrite = useAllowedToWrite();

const _ = useContext(LocalizationContext);

const sharers = useSharers({ configuration, _ });
Expand Down Expand Up @@ -544,7 +551,7 @@ export default function Item({ currentTime, item, selected, expanded, setNavExpa
target="_blank"
rel="noreferrer"
accessKey="o"
onClick={stopPropagation}
onClick={externalLinkOnClick}
>
<FontAwesomeIcon icon={icons.openWindow} /> {_('open_window')}
</a>
Expand Down Expand Up @@ -599,7 +606,7 @@ export default function Item({ currentTime, item, selected, expanded, setNavExpa
target="_blank"
rel="noreferrer"
accessKey="o"
onClick={stopPropagation}
onClick={externalLinkOnClick}
>
<FontAwesomeIcon icon={icons.openWindow} /> {_('open_window')}
</a>
Expand Down