about summary refs log tree commit diff
path: root/src/view/com/modals/Modal.web.tsx
blob: 44ea95f071668fddf537b4d046071e62bd4e07b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import React from 'react'
import {TouchableWithoutFeedback, StyleSheet, View} from 'react-native'
import {observer} from 'mobx-react-lite'
import {useStores} from '../../../state'
import {usePalette} from '../../lib/hooks/usePalette'

import * as models from '../../../state/models/shell-ui'

import * as ConfirmModal from './Confirm'
import * as EditProfileModal from './EditProfile'
import * as ServerInputModal from './ServerInput'
import * as ReportPostModal from './ReportPost'
import * as ReportAccountModal from './ReportAccount'
import * as CropImageModal from './crop-image/CropImage.web'

export const Modal = observer(function Modal() {
  const store = useStores()
  const pal = usePalette('default')

  if (!store.shell.isModalActive) {
    return null
  }

  const onClose = () => {
    store.shell.closeModal()
  }
  const onInnerPress = () => {
    // do nothing, we just want to stop it from bubbling
  }

  let element
  if (store.shell.activeModal?.name === 'confirm') {
    element = (
      <ConfirmModal.Component
        {...(store.shell.activeModal as models.ConfirmModal)}
      />
    )
  } else if (store.shell.activeModal?.name === 'edit-profile') {
    element = (
      <EditProfileModal.Component
        {...(store.shell.activeModal as models.EditProfileModal)}
      />
    )
  } else if (store.shell.activeModal?.name === 'server-input') {
    element = (
      <ServerInputModal.Component
        {...(store.shell.activeModal as models.ServerInputModal)}
      />
    )
  } else if (store.shell.activeModal?.name === 'report-post') {
    element = <ReportPostModal.Component />
  } else if (store.shell.activeModal?.name === 'report-account') {
    element = <ReportAccountModal.Component />
  } else if (store.shell.activeModal?.name === 'crop-image') {
    element = (
      <CropImageModal.Component
        {...(store.shell.activeModal as models.CropImageModal)}
      />
    )
  } else {
    return null
  }

  return (
    <TouchableWithoutFeedback onPress={onClose}>
      <View style={styles.mask}>
        <TouchableWithoutFeedback onPress={onInnerPress}>
          <View style={[styles.container, pal.view]}>{element}</View>
        </TouchableWithoutFeedback>
      </View>
    </TouchableWithoutFeedback>
  )
})

const styles = StyleSheet.create({
  mask: {
    position: 'absolute',
    top: 0,
    left: 0,
    width: '100%',
    height: '100%',
    backgroundColor: '#000c',
    alignItems: 'center',
    justifyContent: 'center',
  },
  container: {
    width: 500,
    paddingVertical: 20,
    paddingHorizontal: 24,
    borderRadius: 8,
  },
})