chat ui list
parent
0a07a80b0a
commit
caf6f5ebf6
|
@ -20,6 +20,7 @@ import {initKey} from '@caj/helper/storage/bdm/encryption';
|
||||||
import UserManager from '@caj/user/UserManager';
|
import UserManager from '@caj/user/UserManager';
|
||||||
import MyUserManager from '@caj/user/MyUserManager';
|
import MyUserManager from '@caj/user/MyUserManager';
|
||||||
import DBSchemas from '@caj/helper/storage/bdm/schemas';
|
import DBSchemas from '@caj/helper/storage/bdm/schemas';
|
||||||
|
import {chatType} from '@caj/components/chat/types';
|
||||||
|
|
||||||
const AnimationView = animated(View);
|
const AnimationView = animated(View);
|
||||||
|
|
||||||
|
@ -32,9 +33,9 @@ function onAppStart() {
|
||||||
console.log('finish');
|
console.log('finish');
|
||||||
await BigDataManager.databases.users.setEntry({
|
await BigDataManager.databases.users.setEntry({
|
||||||
UserId: 'test',
|
UserId: 'test',
|
||||||
AccountName: 'test222222222',
|
AccountName: 'TestAcc',
|
||||||
Username: 'us',
|
Username: 'TestAccountVirtual',
|
||||||
Description: 'daw',
|
Description: 'This is a test account that is not real. ^^',
|
||||||
FollowersCount: 2,
|
FollowersCount: 2,
|
||||||
FollowingCount: 24,
|
FollowingCount: 24,
|
||||||
lastUpdateTimestamp: 412341234,
|
lastUpdateTimestamp: 412341234,
|
||||||
|
@ -48,6 +49,21 @@ function onAppStart() {
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
appNonSaveVarActions.setAppStatus(appStatus.APP_RUNNING),
|
appNonSaveVarActions.setAppStatus(appStatus.APP_RUNNING),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
store.dispatch(
|
||||||
|
appNonSaveVarActions.setChatEntity({
|
||||||
|
id: MyUserManager.getSelectedUserId(),
|
||||||
|
type: chatType.User,
|
||||||
|
tags: [],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
store.dispatch(
|
||||||
|
appNonSaveVarActions.setChatEntity({
|
||||||
|
id: 'test',
|
||||||
|
type: chatType.User,
|
||||||
|
tags: [],
|
||||||
|
}),
|
||||||
|
);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error("Database Error! Can't start App :(", err);
|
console.error("Database Error! Can't start App :(", err);
|
||||||
|
|
|
@ -63,15 +63,21 @@ const validateEmail = (email: EMail) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function NotLoggedIn() {
|
export default function NotLoggedIn() {
|
||||||
|
const currentUser = useSelector(
|
||||||
|
(state: RootState) => state.appVariables.preferences.selectedAccount,
|
||||||
|
);
|
||||||
|
|
||||||
const lang = useSelector((state: RootState) => state.appVariables.lang);
|
const lang = useSelector((state: RootState) => state.appVariables.lang);
|
||||||
const theme = useSelector(
|
const theme = useSelector(
|
||||||
(state: RootState) => state.appVariables.preferences.theme,
|
(state: RootState) => state.appVariables.preferences.theme,
|
||||||
);
|
);
|
||||||
|
|
||||||
const toast = useToast();
|
|
||||||
|
|
||||||
const navigation = useNavigation<RootScreenNavigationProp>();
|
const navigation = useNavigation<RootScreenNavigationProp>();
|
||||||
|
|
||||||
|
if (currentUser !== 'none') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box alignItems="center" mt={5}>
|
<Box alignItems="center" mt={5}>
|
||||||
<Text color="primary.400">{lang.appName}</Text>
|
<Text color="primary.400">{lang.appName}</Text>
|
||||||
|
|
|
@ -14,8 +14,8 @@ export function ProfilePicture(props: {size: number; UserId: UserId}) {
|
||||||
return (
|
return (
|
||||||
<Skeleton
|
<Skeleton
|
||||||
bg={'black.200'}
|
bg={'black.200'}
|
||||||
width={size}
|
width={size + 'px'}
|
||||||
height={size}
|
height={size + 'px'}
|
||||||
style={{borderRadius: size / 2}}></Skeleton>
|
style={{borderRadius: size / 2}}></Skeleton>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -55,15 +55,15 @@ export function ProfilePicture(props: {size: number; UserId: UserId}) {
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
bg={'hsl(' + hash + ', 70%, 60%)'}
|
bg={'hsl(' + hash + ', 70%, 60%)'}
|
||||||
width={size}
|
width={size + 'px'}
|
||||||
height={size}
|
height={size + 'px'}
|
||||||
style={{borderRadius: size / 2}}>
|
style={{borderRadius: size / 2}}>
|
||||||
<Text
|
<Text
|
||||||
color={'#fff'}
|
color={'#fff'}
|
||||||
textAlign={'center'}
|
textAlign={'center'}
|
||||||
width={size}
|
width={size + 'px'}
|
||||||
height={size}
|
height={size + 'px'}
|
||||||
lineHeight={size}
|
lineHeight={size + 'px'}
|
||||||
fontSize={size * 0.75 + 'px'}>
|
fontSize={size * 0.75 + 'px'}>
|
||||||
{firstLetter.toUpperCase()}
|
{firstLetter.toUpperCase()}
|
||||||
</Text>
|
</Text>
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
import {RootState} from '@caj/redux/store';
|
||||||
|
import UserManager from '@caj/user/UserManager';
|
||||||
|
import {Box, HStack, Text, VStack} from 'native-base';
|
||||||
|
import {useSelector} from 'react-redux';
|
||||||
|
import {ProfilePicture} from '../ProfilePicture';
|
||||||
|
import {TextSkeleton} from '../simple/Skeleton';
|
||||||
|
import {chatType} from './types';
|
||||||
|
|
||||||
|
export function ListChats() {
|
||||||
|
const chats = useSelector((state: RootState) => state.nonSaveVariables.chats);
|
||||||
|
const chatActivity = useSelector(
|
||||||
|
(state: RootState) => state.nonSaveVariables.chatActivity,
|
||||||
|
);
|
||||||
|
|
||||||
|
const space = 4;
|
||||||
|
const ppSize = 64;
|
||||||
|
const tagSize = 24;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<VStack space={space + 'px'} width="100%" marginY={space + 'px'}>
|
||||||
|
{chatActivity.map((chatId, i) => {
|
||||||
|
const chat = chats[chatId];
|
||||||
|
if (chat.type === chatType.User) {
|
||||||
|
const user = UserManager.getUserSelector(chatId);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
key={'chatList_i' + i + chatId}
|
||||||
|
bg={'black.400'}
|
||||||
|
borderTopRadius={ppSize / 2 + 'px'}
|
||||||
|
borderBottomRightRadius={ppSize / 2 + 'px'}
|
||||||
|
borderBottomLeftRadius={tagSize / 2 + 'px'}
|
||||||
|
marginX={space + 'px'}
|
||||||
|
padding={space + 'px'}>
|
||||||
|
<VStack space={space + 'px'}>
|
||||||
|
<HStack space={space + 'px'}>
|
||||||
|
<ProfilePicture
|
||||||
|
UserId={chatId}
|
||||||
|
size={ppSize}></ProfilePicture>
|
||||||
|
<VStack>
|
||||||
|
<TextSkeleton
|
||||||
|
lineHeight={ppSize / 2.5 + 'px'}
|
||||||
|
numberOfLines={1}
|
||||||
|
SkeletonProps={{
|
||||||
|
lines: 1,
|
||||||
|
width: '160px',
|
||||||
|
}}
|
||||||
|
color="primary.400">
|
||||||
|
{user.Username.data}
|
||||||
|
</TextSkeleton>
|
||||||
|
<TextSkeleton
|
||||||
|
lineHeight={ppSize / 2.5 + 'px'}
|
||||||
|
numberOfLines={1}
|
||||||
|
SkeletonProps={{
|
||||||
|
lines: 1,
|
||||||
|
width: '160px',
|
||||||
|
}}
|
||||||
|
color="white.400">
|
||||||
|
{user.Username.data}
|
||||||
|
</TextSkeleton>
|
||||||
|
</VStack>
|
||||||
|
</HStack>
|
||||||
|
<HStack>
|
||||||
|
<Box
|
||||||
|
height={tagSize + 'px'}
|
||||||
|
paddingX={tagSize / 2 + 'px'}
|
||||||
|
borderRadius={tagSize / 2}
|
||||||
|
bg={'lime.300'}>
|
||||||
|
<Text color={'#000'} lineHeight={tagSize + 'px'}>
|
||||||
|
Friend
|
||||||
|
</Text>
|
||||||
|
</Box>
|
||||||
|
</HStack>
|
||||||
|
</VStack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})}
|
||||||
|
</VStack>
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { UserId } from "@caj/configs/types"
|
||||||
|
|
||||||
|
type GroupId = string;
|
||||||
|
|
||||||
|
export enum chatType {
|
||||||
|
User = 0,
|
||||||
|
Group = 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum chatTags {
|
||||||
|
FRIEND,
|
||||||
|
GROUP,
|
||||||
|
GOOD_FRIENDS,
|
||||||
|
}
|
||||||
|
|
||||||
|
export type chatId = UserId | GroupId;
|
||||||
|
|
||||||
|
export interface chatEntity {
|
||||||
|
type: chatType;
|
||||||
|
id: chatId;
|
||||||
|
title?: string;
|
||||||
|
tags: chatTags[];
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
//these variables should not changed by the user and will not be saved in storage
|
//these variables should not changed by the user and will not be saved in storage
|
||||||
|
|
||||||
|
import { chatEntity, chatId } from '@caj/components/chat/types';
|
||||||
import {getVersionByNum, VersionType} from '@caj/helper/version';
|
import {getVersionByNum, VersionType} from '@caj/helper/version';
|
||||||
import {User} from '@caj/user/types';
|
import {User} from '@caj/user/types';
|
||||||
import {UserId} from './types';
|
import {UserId} from './types';
|
||||||
|
@ -25,6 +26,8 @@ export interface NON_SAVE_VARS {
|
||||||
appStatus: appStatus;
|
appStatus: appStatus;
|
||||||
connectionStatus: connectionStatus;
|
connectionStatus: connectionStatus;
|
||||||
cachedUsers: {[key: UserId]: User};
|
cachedUsers: {[key: UserId]: User};
|
||||||
|
chats: {[key: chatId]: chatEntity}
|
||||||
|
chatActivity: chatId[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const non_save_vars: NON_SAVE_VARS = {
|
export const non_save_vars: NON_SAVE_VARS = {
|
||||||
|
@ -32,4 +35,6 @@ export const non_save_vars: NON_SAVE_VARS = {
|
||||||
appStatus: appStatus.IS_LOADING,
|
appStatus: appStatus.IS_LOADING,
|
||||||
connectionStatus: connectionStatus.UNKNOWN,
|
connectionStatus: connectionStatus.UNKNOWN,
|
||||||
cachedUsers: {},
|
cachedUsers: {},
|
||||||
|
chats: {},
|
||||||
|
chatActivity: [],
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,6 +4,7 @@ import type {PayloadAction} from '@reduxjs/toolkit';
|
||||||
import {appStatus, non_save_vars} from './appNonSaveVar';
|
import {appStatus, non_save_vars} from './appNonSaveVar';
|
||||||
import {User} from '@caj/user/types';
|
import {User} from '@caj/user/types';
|
||||||
import {UserId} from './types';
|
import {UserId} from './types';
|
||||||
|
import {chatEntity, chatId} from '@caj/components/chat/types';
|
||||||
|
|
||||||
export const appNonSaveVariablesSlice = createSlice({
|
export const appNonSaveVariablesSlice = createSlice({
|
||||||
name: 'non_save_vars',
|
name: 'non_save_vars',
|
||||||
|
@ -18,6 +19,32 @@ export const appNonSaveVariablesSlice = createSlice({
|
||||||
removeCachedUser: (state, action: PayloadAction<UserId>) => {
|
removeCachedUser: (state, action: PayloadAction<UserId>) => {
|
||||||
delete state.cachedUsers[action.payload];
|
delete state.cachedUsers[action.payload];
|
||||||
},
|
},
|
||||||
|
setChatEntity: (state, action: PayloadAction<chatEntity>) => {
|
||||||
|
const chatId = action.payload.id;
|
||||||
|
|
||||||
|
state.chats[chatId] = action.payload;
|
||||||
|
|
||||||
|
if (state.chatActivity.includes(chatId) === false)
|
||||||
|
state.chatActivity.unshift(chatId);
|
||||||
|
},
|
||||||
|
changeChatEntity: (state, action: PayloadAction<chatEntity>) => {
|
||||||
|
const chatId = action.payload.id;
|
||||||
|
|
||||||
|
state.chats[chatId] = action.payload;
|
||||||
|
|
||||||
|
if (state.chatActivity.includes(chatId) === false)
|
||||||
|
state.chatActivity.unshift(chatId);
|
||||||
|
state.chatActivity.sort(function (x, y) {
|
||||||
|
return x == chatId ? -1 : y == chatId ? 1 : 0;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
removeChatEntity: (state, action: PayloadAction<chatId>) => {
|
||||||
|
delete state.chats[action.payload];
|
||||||
|
|
||||||
|
state.chatActivity = state.chatActivity.filter(function (ele) {
|
||||||
|
return ele !== action.payload;
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ export const lang: LangFormat = {
|
||||||
home: {
|
home: {
|
||||||
account: 'My account',
|
account: 'My account',
|
||||||
calendar: 'Calendar',
|
calendar: 'Calendar',
|
||||||
chat: 'Conversations',
|
chat: 'Chats',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
info: 'Info',
|
info: 'Info',
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import {ListChats} from '@caj/components/chat/listChats';
|
||||||
import NotLoggedIn from '@caj/components/NotLoggedIn';
|
import NotLoggedIn from '@caj/components/NotLoggedIn';
|
||||||
import {defaultHeaderStyle} from '@caj/configs/colors';
|
import {defaultHeaderStyle} from '@caj/configs/colors';
|
||||||
import {RootStackNavigatorParamList} from '@caj/Navigation';
|
import {RootStackNavigatorParamList} from '@caj/Navigation';
|
||||||
|
@ -44,6 +45,7 @@ function ChatTab() {
|
||||||
function ChatScreen() {
|
function ChatScreen() {
|
||||||
return (
|
return (
|
||||||
<Center>
|
<Center>
|
||||||
|
<ListChats />
|
||||||
<NotLoggedIn />
|
<NotLoggedIn />
|
||||||
</Center>
|
</Center>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue