11import { useState , useCallback , useEffect } from 'react' ;
2- import { ScrollView , Linking , Alert , ActivityIndicator } from 'react-native' ;
2+ import { ScrollView , Linking , ActivityIndicator } from 'react-native' ;
33import { Ionicons } from '@expo/vector-icons' ;
44import {
55 Screen ,
@@ -28,6 +28,7 @@ import {
2828import { types } from '@polycentric/react-native' ;
2929import { useTheme } from '@/theme' ;
3030import { TAB_BAR_HEIGHT , SOURCE_CODE_URL , REPORT_BUG_URL } from '@/constants' ;
31+ import { confirm } from '@/lib/dialogs/alert' ;
3132
3233export default function Settings ( ) {
3334 const { theme } = useTheme ( ) ;
@@ -82,7 +83,7 @@ export default function Settings() {
8283function IdentitySettingsContent ( {
8384 publicKey,
8485} : {
85- publicKey : types . IPublicKey ;
86+ publicKey : types . PublicKey ;
8687} ) {
8788 const { theme } = useTheme ( ) ;
8889 const client = usePolycentric ( ) ;
@@ -93,11 +94,37 @@ function IdentitySettingsContent({
9394 const [ editing , setEditing ] = useState ( false ) ;
9495 const [ nameDraft , setNameDraft ] = useState ( '' ) ;
9596 const [ saving , setSaving ] = useState ( false ) ;
97+ const [ eventCount , setEventCount ] = useState ( 0 ) ;
9698
9799 useEffect ( ( ) => {
98100 setNameDraft ( username ) ;
99101 } , [ username ] ) ;
100102
103+ useEffect ( ( ) => {
104+ let cancelled = false ;
105+
106+ client . storage . processStates
107+ . getCurrentLogicalClock (
108+ client . currentIdentity . keyPair . keyType ,
109+ client . currentIdentity . keyPair . publicKey . key ,
110+ client . process . process ,
111+ )
112+ . then ( ( logicalClock ) => {
113+ if ( ! cancelled ) {
114+ setEventCount ( Number ( logicalClock ) ) ;
115+ }
116+ } )
117+ . catch ( ( ) => {
118+ if ( ! cancelled ) {
119+ setEventCount ( 0 ) ;
120+ }
121+ } ) ;
122+
123+ return ( ) => {
124+ cancelled = true ;
125+ } ;
126+ } , [ client , identity ] ) ;
127+
101128 const handleSave = useCallback ( async ( ) => {
102129 setSaving ( true ) ;
103130 try {
@@ -125,7 +152,6 @@ function IdentitySettingsContent({
125152 )
126153 : '' ;
127154 const displayName = username ;
128- const eventCount = Math . max ( 0 , client . logicalClock - 1 ) ;
129155 const avatarUrl = identiconUrl ( publicKey , 160 ) ;
130156
131157 return (
@@ -261,27 +287,24 @@ function ServersSheetContent() {
261287 }
262288 } ;
263289
264- const handleRemoveServer = ( server : string ) => {
265- Alert . alert ( 'Remove Server' , `Remove ${ server } ?` , [
266- { text : 'Cancel' , style : 'cancel' } ,
267- {
268- text : 'Remove' ,
269- style : 'destructive' ,
270- onPress : async ( ) => {
271- setIsBusy ( true ) ;
272- try {
273- await client . contentManager . createRemoveServer ( server ) ;
274- refreshServers ( ) ;
275- store . getState ( ) . clearFeed ( 'explore' ) ;
276- client . sync ( ) . catch ( ( ) => { } ) ;
277- } catch ( err ) {
278- console . error ( 'Failed to remove server:' , err ) ;
279- } finally {
280- setIsBusy ( false ) ;
281- }
282- } ,
283- } ,
284- ] ) ;
290+ const handleRemoveServer = async ( server : string ) => {
291+ const ok = await confirm ( {
292+ title : 'Remove Server' ,
293+ message : `Remove ${ server } ?` ,
294+ confirmText : 'Remove' ,
295+ } ) ;
296+ if ( ! ok ) return ;
297+ setIsBusy ( true ) ;
298+ try {
299+ await client . contentManager . createRemoveServer ( server ) ;
300+ refreshServers ( ) ;
301+ store . getState ( ) . clearFeed ( 'explore' ) ;
302+ client . sync ( ) . catch ( ( ) => { } ) ;
303+ } catch ( err ) {
304+ console . error ( 'Failed to remove server:' , err ) ;
305+ } finally {
306+ setIsBusy ( false ) ;
307+ }
285308 } ;
286309
287310 return (
0 commit comments