useImPopup.ts 840 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { reactive, readonly } from 'vue'
  2. export interface ImPopupState {
  3. visible: boolean
  4. /**
  5. * When provided, IM popup should open conversation detail for this userId (C2C).
  6. * This value is consumed by `components/popup/Im.vue`.
  7. */
  8. targetUserId: string | null
  9. }
  10. const state = reactive<ImPopupState>({
  11. visible: false,
  12. targetUserId: null,
  13. })
  14. const open = () => {
  15. state.visible = true
  16. state.targetUserId = null
  17. }
  18. const openConversation = (userId: string) => {
  19. state.targetUserId = userId ? String(userId) : null
  20. state.visible = true
  21. }
  22. const clearTarget = () => {
  23. state.targetUserId = null
  24. }
  25. const close = () => {
  26. state.visible = false
  27. state.targetUserId = null
  28. }
  29. export const useImPopup = () => {
  30. return {
  31. state: readonly(state),
  32. open,
  33. openConversation,
  34. clearTarget,
  35. close,
  36. }
  37. }