more work on trying to get focus saving to work

This commit is contained in:
Nolan Lawson 2018-02-10 12:34:54 -08:00
parent 820d77a78f
commit 2efcb16bcc
7 changed files with 32 additions and 26 deletions

View File

@ -141,6 +141,7 @@
parentElement.parentElement.localName !== 'button') { parentElement.parentElement.localName !== 'button') {
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()
this.store.setForCurrentTimeline({ignoreBlurEvents: true})
goto(`/statuses/${this.get('statusId')}`) goto(`/statuses/${this.get('statusId')}`)
} }
} }

View File

@ -1,5 +1,7 @@
<a class="status-author-name {{isStatusInNotification ? 'status-in-notification' : '' }} {{isStatusInOwnThread ? 'status-in-own-thread' : ''}}" <a class="status-author-name {{isStatusInNotification ? 'status-in-notification' : '' }} {{isStatusInOwnThread ? 'status-in-own-thread' : ''}}"
href="/accounts/{{status.account.id}}"> href="/accounts/{{status.account.id}}"
focus-key="{{focusKey}}"
>
{{status.account.display_name || status.account.username}} {{status.account.display_name || status.account.username}}
</a> </a>
<style> <style>
@ -31,27 +33,10 @@
</style> </style>
<script> <script>
import IntlRelativeFormat from 'intl-relativeformat'
import ExternalLink from '../ExternalLink.html'
import { mark, stop } from '../../_utils/marks'
const relativeFormat = new IntlRelativeFormat('en-US');
export default { export default {
helpers: {
getClass: isStatusInNotification => isStatusInNotification ? 'status-author-in-notification' : ''
},
computed: { computed: {
createdAtDate: (status) => status.created_at, statusId: (status) => status.id,
relativeDate: (createdAtDate) => { focusKey: (statusId) => `status-author-name-${statusId}`
mark('compute relativeDate')
let res = relativeFormat.format(new Date(createdAtDate))
stop('compute relativeDate')
return res
}
},
components: {
ExternalLink
} }
} }
</script> </script>

View File

@ -3,7 +3,9 @@
<use xlink:href="{{getIcon(notification, status)}}"/> <use xlink:href="{{getIcon(notification, status)}}"/>
</svg> </svg>
<span> <span>
<a href="/accounts/{{getAccount(notification, status).id}}"> <a href="/accounts/{{getAccount(notification, status).id}}"
focus-key="{{focusKey}}"
>
{{getAccount(notification, status).display_name || ('@' + getAccount(notification, status).username)}} {{getAccount(notification, status).display_name || ('@' + getAccount(notification, status).username)}}
</a> </a>
{{#if notification && notification.type === 'reblog'}} {{#if notification && notification.type === 'reblog'}}
@ -62,6 +64,10 @@
</style> </style>
<script> <script>
export default { export default {
computed: {
statusId: (status) => status.id,
focusKey: (statusId) => `status-header-${statusId}`
},
helpers: { helpers: {
getIcon(notification, status) { getIcon(notification, status) {
if ((notification && notification.type === 'reblog') || (status && status.reblog)) { if ((notification && notification.type === 'reblog') || (status && status.reblog)) {

View File

@ -1,5 +1,7 @@
<a class="status-relative-date {{isStatusInNotification ? 'status-in-notification' : '' }}" <a class="status-relative-date {{isStatusInNotification ? 'status-in-notification' : '' }}"
href="/statuses/{{status.id}}"> href="/statuses/{{status.id}}"
focus-key="{{focusKey}}"
>
<time datetime={{createdAtDate}} title="{{relativeDate}}" aria-label="{{relativeDate}} click to show thread">{{relativeDate}}</time> <time datetime={{createdAtDate}} title="{{relativeDate}}" aria-label="{{relativeDate}} click to show thread">{{relativeDate}}</time>
</a> </a>
<style> <style>
@ -32,12 +34,14 @@
export default { export default {
computed: { computed: {
createdAtDate: (status) => status.created_at, createdAtDate: (status) => status.created_at,
statusId: (status) => status.id,
relativeDate: (createdAtDate) => { relativeDate: (createdAtDate) => {
mark('compute relativeDate') mark('compute relativeDate')
let res = relativeFormat.format(new Date(createdAtDate)) let res = relativeFormat.format(new Date(createdAtDate))
stop('compute relativeDate') stop('compute relativeDate')
return res return res
} },
focusKey: (statusId) => `status-relative-date-${statusId}`
} }
} }
</script> </script>

View File

@ -65,9 +65,9 @@
export default { export default {
oncreate() { oncreate() {
console.log('timeline oncreate()') console.log('timeline oncreate()')
this.store.setForCurrentTimeline({ignoreBlurEvents: false})
setupTimeline() setupTimeline()
if (this.store.get('initialized')) { if (this.store.get('initialized')) {
console.log('initialized!!!!')
this.restoreFocus() this.restoreFocus()
} }
}, },
@ -159,12 +159,15 @@
}) })
}, },
clearFocus() { clearFocus() {
/*console.log('clearing focus') if (this.store.get('ignoreBlurEvents')) {
return
}
console.log('clearing focus')
let instanceName = this.store.get('currentInstance') let instanceName = this.store.get('currentInstance')
let timelineName = this.get('timeline') let timelineName = this.get('timeline')
this.store.setForTimeline(instanceName, timelineName, { this.store.setForTimeline(instanceName, timelineName, {
lastFocusedElementSelector: null lastFocusedElementSelector: null
})*/ })
}, },
restoreFocus() { restoreFocus() {
let lastFocusedElementSelector = this.store.get('lastFocusedElementSelector') let lastFocusedElementSelector = this.store.get('lastFocusedElementSelector')

View File

@ -12,6 +12,12 @@ function timelineMixins (Store) {
let timelineData = timelines[instanceName] || {} let timelineData = timelines[instanceName] || {}
return (timelineData[timelineName] || {})[key] return (timelineData[timelineName] || {})[key]
} }
Store.prototype.setForCurrentTimeline = function (obj) {
let instanceName = this.get('currentInstance')
let timelineName = this.get('currentTimeline')
this.setForTimeline(instanceName, timelineName, obj)
}
} }
export function mixins (Store) { export function mixins (Store) {

View File

@ -14,6 +14,7 @@ export function timelineComputations (store) {
computeForTimeline(store, 'runningUpdate') computeForTimeline(store, 'runningUpdate')
computeForTimeline(store, 'initialized') computeForTimeline(store, 'initialized')
computeForTimeline(store, 'lastFocusedElementSelector') computeForTimeline(store, 'lastFocusedElementSelector')
computeForTimeline(store, 'ignoreBlurEvents')
store.compute('lastTimelineItemId', ['timelineItemIds'], (timelineItemIds) => timelineItemIds && timelineItemIds.length && timelineItemIds[timelineItemIds.length - 1]) store.compute('lastTimelineItemId', ['timelineItemIds'], (timelineItemIds) => timelineItemIds && timelineItemIds.length && timelineItemIds[timelineItemIds.length - 1])
} }