about summary refs log tree commit diff
path: root/src/view/com/util/Alert.web.tsx
diff options
context:
space:
mode:
authorAnsh <anshnanda10@gmail.com>2023-04-25 12:01:47 -0700
committerGitHub <noreply@github.com>2023-04-25 14:01:47 -0500
commit01410ad4bfb5e49aa954ee2e65964a43b1aaf401 (patch)
tree551fb734cef583d7d4a6fc195fea5d3cb058024d /src/view/com/util/Alert.web.tsx
parentb00365c196ba4709f90e9d90b0f8757248c0189e (diff)
downloadvoidsky-01410ad4bfb5e49aa954ee2e65964a43b1aaf401.tar.zst
create Alert.tsx and Alert.web.tsx and replace uses (#513)
Diffstat (limited to 'src/view/com/util/Alert.web.tsx')
-rw-r--r--src/view/com/util/Alert.web.tsx23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/view/com/util/Alert.web.tsx b/src/view/com/util/Alert.web.tsx
new file mode 100644
index 000000000..94ccc7e43
--- /dev/null
+++ b/src/view/com/util/Alert.web.tsx
@@ -0,0 +1,23 @@
+import {AlertButton, AlertStatic} from 'react-native'
+
+class WebAlert implements Pick<AlertStatic, 'alert'> {
+  public alert(title: string, message?: string, buttons?: AlertButton[]): void {
+    if (buttons === undefined || buttons.length === 0) {
+      window.alert([title, message].filter(Boolean).join('\n'))
+      return
+    }
+
+    const result = window.confirm([title, message].filter(Boolean).join('\n'))
+
+    if (result === true) {
+      const confirm = buttons.find(({style}) => style !== 'cancel')
+      confirm?.onPress?.()
+      return
+    }
+
+    const cancel = buttons.find(({style}) => style === 'cancel')
+    cancel?.onPress?.()
+  }
+}
+
+export const Alert = new WebAlert()