Skip to content
Merged
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
8 changes: 8 additions & 0 deletions api/TPEN.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ class Tpen {
eventDispatcher.on("tpen-user-loaded", ev => this.currentUser = ev.detail)
eventDispatcher.on("tpen-project-loaded", ev => this.activeProject = ev.detail)

// Centralized token expiration UX: notify user and redirect to login
let expirationTimeout = null
eventDispatcher.on('token-expiration', () => {
if (expirationTimeout) return
eventDispatcher.dispatch('tpen-toast', { status: 'error', message: 'Your session has expired. Redirecting to login...' })
expirationTimeout = setTimeout(() => this.login(), 4000)
})

if (this.screen.projectInQuery) {
try {
import('./Project.js').then(module => {
Expand Down
3 changes: 2 additions & 1 deletion components/new-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ class NewAction extends HTMLElement {
}

TPEN2ImportHandler = async () => {
const userToken = localStorage.getItem("userToken")
const userToken = TPEN.getAuthorization()
if (!userToken) return TPEN.login()
let tokenDomain
let isProdTPEN

Expand Down
14 changes: 9 additions & 5 deletions interfaces/manage-columns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,11 @@ class TpenManageColumns extends HTMLElement {

connectedCallback() {
TPEN.attachAuthentication(this)
localStorage.removeItem('annotationsState')
if (!TPEN.screen.projectInQuery) {
this.showError("No project id provided")
return
}
localStorage.removeItem(`annotationsState:${TPEN.screen.projectInQuery}`)
if (!TPEN.screen.pageInQuery) {
this.showError("No page id provided")
return
Expand Down Expand Up @@ -403,7 +407,7 @@ class TpenManageColumns extends HTMLElement {
}))
})
this.totalIds = annotations.filter(anno => !assignedAnnotationIds.some(a => a.lineId === anno.lineId)).map(a => a.lineId)
localStorage.setItem('annotationsState', JSON.stringify({
localStorage.setItem(`annotationsState:${TPEN.screen.projectInQuery}`, JSON.stringify({
remainingIDs: this.totalIds,
selectedIDs: []
}))
Expand Down Expand Up @@ -526,7 +530,7 @@ class TpenManageColumns extends HTMLElement {
this.totalIds = this.cachedAnnotations
.filter(anno => !assignedAnnotationIds.some(a => a.lineId === anno.lineId))
.map(a => a.lineId)
localStorage.setItem('annotationsState', JSON.stringify({
localStorage.setItem(`annotationsState:${TPEN.screen.projectInQuery}`, JSON.stringify({
remainingIDs: this.totalIds,
selectedIDs: []
}))
Expand Down Expand Up @@ -927,7 +931,7 @@ class TpenManageColumns extends HTMLElement {
}

restoreAnnotationState() {
const saved = localStorage.getItem('annotationsState')
const saved = localStorage.getItem(`annotationsState:${TPEN.screen.projectInQuery}`)
if (!saved) return
const { selectedIDs = [] } = JSON.parse(saved)
const boxes = Array.from(this.shadowRoot.querySelectorAll('.overlayBox'))
Expand Down Expand Up @@ -1023,7 +1027,7 @@ class TpenManageColumns extends HTMLElement {
const selectedIDs = this.selectedBoxes.map(b => b.dataset.lineId)
const remainingIDs = this.totalIds.filter(id => !this.selectedBoxes.some(b => b.dataset.lineId === id))
try {
localStorage.setItem('annotationsState', JSON.stringify({ remainingIDs, selectedIDs }))
localStorage.setItem(`annotationsState:${TPEN.screen.projectInQuery}`, JSON.stringify({ remainingIDs, selectedIDs }))
} catch (e) {
// localStorage may be unavailable (e.g., private mode, quota exceeded)
// Silent fail as this is just a convenience feature
Expand Down
Loading