Skip to content

Add Pinia stores and dependencies. (Fixes #2)#15

Open
Sancus wants to merge 1 commit intomainfrom
pr/pinia-stores
Open

Add Pinia stores and dependencies. (Fixes #2)#15
Sancus wants to merge 1 commit intomainfrom
pr/pinia-stores

Conversation

@Sancus
Copy link
Copy Markdown
Member

@Sancus Sancus commented Feb 24, 2026

Split the store into:

  • auth-store: OIDC init, JMAP client, connection state
  • email-store: mailboxes, message list (vue-query), detail, delta sync
  • compose-store: compose state, identities, send logic

Split the store into:

- auth-store: OIDC init, JMAP client, connection state
- email-store: mailboxes, message list (vue-query), detail, delta sync
- compose-store: compose state, identities, send logic
@Sancus Sancus requested a review from MelissaAutumn February 24, 2026 21:08
Copy link
Copy Markdown
Member

@MelissaAutumn MelissaAutumn left a comment

Choose a reason for hiding this comment

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

No dom manip in stores please.

They're storage containers for things like state. They should store a raw-ish state, and using computed turn that state into something more processed.

If you need to act on that state there should be functions in the store that do it for you.

That's not to say Appointment/Accounts does this 100%, but it's generally what stores are for. I tend to shove any convenience functions that are related to the state as well.

Given the state of this code, you should probably write these from scratch based on what you need to do from the main app with those concepts in mind.

Also these need comments, written by humans pls.

const client = ref(null)
const connected = ref(false)
const status = ref('Not connected.')
const error = ref('')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should probably be null.

} catch (e) {
status.value = 'Failed.'
error.value =
e.message +
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

es6 string literals pls.

})
await client.value.fetchSession()
connected.value = true
document.body.classList.add('connected')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can be inferred based on the oidc status enum on whatever is consuming this store. No dom manip in stores!

const status = ref('Not connected.')
const error = ref('')
const oidcReady = ref(false)
const oidcLoading = ref(true)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are these states independant of each other? You can merge it into an enum. (You're not using typescript but you can still create a object with the values.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ex/

const OIDC_LOADING_STATE = {
  NOT_CONNECTED: 'not_connected',
  FAILED: 'failed',
  CONNECTING: 'connecting',
  READY: 'ready',
};

Set it in your code like so:

oidcLoadingStatus.value = OIDC_LOADING_STATE.CONNECTING;

Then in your l10n you can simply have a computed that returns return l10n(`status_codes.${oidcLoadingStatus}`).

export const useAuthStore = defineStore('auth', () => {
const client = ref(null)
const connected = ref(false)
const status = ref('Not connected.')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These can be inferred based on an enum state I mentioned below.


const identities = ref([])
const sending = ref(false)
const composeStatus = ref('')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should be an enum like in auth-store.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Bundle this with a composeLastError for extra points or something.

}
} catch {}
return copy
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm going to say no.

}

function sanitizeForDebug(obj) {
const copy = JSON.parse(JSON.stringify(obj))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

)
}
} catch {}
return issues.join('\n')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please flatten by early short-circuiting.

if (role === 'drafts' || mailboxName === 'drafts') return 'Drafts'
if (role === 'archive' || mailboxName === 'archive' || mailboxName === 'archives') return 'Archives'
if (role === 'inbox' || mailboxName === 'inbox') return 'Inbox'
return m.name || 'Mailbox'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ennuuuuuuuuummmmmm

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants