diff --git a/src/Generic.tsx b/src/Generic.tsx index 2db6a77..3a7bafd 100644 --- a/src/Generic.tsx +++ b/src/Generic.tsx @@ -6,7 +6,7 @@ import FastImage from 'react-native-fast-image'; import MaterialIcon from 'react-native-vector-icons/MaterialIcons'; import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons'; -import {API, Channel, Client, Server} from 'revolt.js'; +import {API, Channel, Client, Message, Server} from 'revolt.js'; import {currentTheme, setTheme, themes, styles} from './Theme'; import { @@ -18,7 +18,12 @@ import { RE_BOT_INVITE, WIKI_URL, } from './lib/consts'; -import {ReplyingMessage, ReportedObject, Setting} from './lib/types'; +import { + DeletableObject, + ReplyingMessage, + ReportedObject, + Setting, +} from './lib/types'; const Image = FastImage; export const app = { @@ -301,7 +306,8 @@ export const app = { `[FUNCTIONS] Tried to run uninitialised function openServerSettings (args: ${s})`, ); }, - setMessageBoxInput: t => {}, + setMessageBoxInput: (t: string | null) => {}, + setEditingMessage: (message: Message) => {}, setReplyingMessages: (m: ReplyingMessage[]) => { console.log( `[FUNCTIONS] Tried to run uninitialised function setReplyingMessages (args: ${m})`, @@ -310,6 +316,9 @@ export const app = { getReplyingMessages: () => { return undefined as unknown as ReplyingMessage[]; }, + /** + * @deprecated Message queuing will be removed/reworked due to the switch of message views + */ pushToQueue: m => {}, joinInvite: async (i: API.InviteResponse) => {}, logOut: () => {}, @@ -317,6 +326,7 @@ export const app = { openChannelContextMenu: (c: Channel | null) => {}, openStatusMenu: (state: boolean) => {}, openReportMenu: (object: ReportedObject | null) => {}, + openDeletionConfirmationModal: (object: DeletableObject | null) => {}, }; export function setFunction(name: string, func: any) { diff --git a/src/Modals.tsx b/src/Modals.tsx index 935d50b..05b7a3c 100644 --- a/src/Modals.tsx +++ b/src/Modals.tsx @@ -8,8 +8,10 @@ import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIc import {API, Channel, Server, User} from 'revolt.js'; import {app, client, openUrl, setFunction} from './Generic'; +import {DeletableObject} from './lib/types'; import {currentTheme} from './Theme'; import {GapView} from './components/layout'; +import {ConfirmDeletionModal} from './components/modals'; import { BotInviteSheet, ChannelInfoSheet, @@ -29,7 +31,9 @@ export const Modals = observer(() => { i: null as any, }); const [settingsVisibility, setSettingsVisibility] = React.useState(false); - const [serverSettingsServer, setServerSettingsServer] = React.useState(null as Server | null) + const [serverSettingsServer, setServerSettingsServer] = React.useState( + null as Server | null, + ); const [inviteServer, setInviteServer] = React.useState({ inviteServer: null, inviteServerCode: '', @@ -38,6 +42,9 @@ export const Modals = observer(() => { inviteServerCode: string; }); const [inviteBot, setInviteBot] = React.useState(null as User | null); + const [deletableObject, setDeletableObject] = React.useState( + null as DeletableObject | null, + ); setFunction('openDirectMessage', async (dm: Channel) => { app.openProfile(null); @@ -52,6 +59,12 @@ export const Modals = observer(() => { setFunction('openServerSettings', async (s: Server | null) => { setServerSettingsServer(s); }); + setFunction( + 'openDeletionConfirmationModal', + async (o: DeletableObject | null) => { + setDeletableObject(o); + }, + ); setFunction('openInvite', async (i: string) => { try { let community = await client.fetchInvite(i); @@ -172,7 +185,25 @@ export const Modals = observer(() => { transparent={true} animationType="slide" onRequestClose={() => setServerSettingsServer(null)}> - setServerSettingsServer(null)} /> + setServerSettingsServer(null)} + /> + + setDeletableObject(null)}> + + + ); diff --git a/src/components/modals/ConfirmDeletionModal.tsx b/src/components/modals/ConfirmDeletionModal.tsx new file mode 100644 index 0000000..2594d3b --- /dev/null +++ b/src/components/modals/ConfirmDeletionModal.tsx @@ -0,0 +1,69 @@ +import React from 'react'; +import {View} from 'react-native'; +import {observer} from 'mobx-react-lite'; + +import {app} from '../../Generic'; +import {DeletableObject} from '../../lib/types'; +import {currentTheme} from '../../Theme'; +import {Button, Text} from '../common/atoms'; +import { set } from 'mobx'; + +export const ConfirmDeletionModal = observer( + ({target}: {target: DeletableObject}) => { + return ( + + Delete {target.type}? + + Are you sure you want to delete{' '} + + {target.type === 'Server' ? target.object.name : 'this message'} + + ? + + This cannot be undone. + + + + + + ); + }, +); diff --git a/src/components/modals/index.ts b/src/components/modals/index.ts new file mode 100644 index 0000000..4520a55 --- /dev/null +++ b/src/components/modals/index.ts @@ -0,0 +1 @@ +export {ConfirmDeletionModal} from "./ConfirmDeletionModal"; diff --git a/src/components/sheets/ServerSettingsSheet.tsx b/src/components/sheets/ServerSettingsSheet.tsx index b40deb0..a702544 100644 --- a/src/components/sheets/ServerSettingsSheet.tsx +++ b/src/components/sheets/ServerSettingsSheet.tsx @@ -125,8 +125,7 @@ export const ServerSettingsSheet = observer( }} /> ) : ( - + @@ -250,7 +249,10 @@ export const ServerSettingsSheet = observer( style={{flex: 1, marginBottom: 10}} backgroundColor={currentTheme.error} onPress={() => { - console.log('sussy'); + app.openDeletionConfirmationModal({ + type: 'Server', + object: server, + }); }}> - - Server descriptions support Markdown formatting. - - - + + Server descriptions support Markdown formatting. + + +