File tree Expand file tree Collapse file tree 5 files changed +26
-12
lines changed
Expand file tree Collapse file tree 5 files changed +26
-12
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ export type User = {
44 profile_picture : string ;
55 userName : string ;
66 uid : string ;
7+ createdAt : number ;
78}
89
910export type AuthState = {
Original file line number Diff line number Diff line change 1+ import { DB_NAME } from "@/utils" ;
12import { ACTION_TYPE , ChatState } from "./types" ;
23
34export const initialState : ChatState = {
45 userList : { } ,
56 isLoading : false ,
6- chatRoomId : "chatRoom" ,
7+ chatRoomId : DB_NAME . CHAT_ROOM ,
78 oneToOneRoomId : "" ,
89} ;
910
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ export type MessageSnapshotResponse = {
1515export type ChatState = {
1616 userList : { [ key : string ] : User } ;
1717 isLoading : boolean ;
18- chatRoomId : string | 'chatRoom' ;
18+ chatRoomId : string ;
1919 oneToOneRoomId : string ;
2020} ;
2121
@@ -38,7 +38,7 @@ type SET_LOADING = {
3838type SET_CHAT_ROOM_ID = {
3939 type : ChatActionType . SET_CHAT_ROOM_ID ;
4040 payload : {
41- chatRoomId : string | 'chatRoom' ;
41+ chatRoomId : string ;
4242 oneToOneRoomId : string ;
4343 } ;
4444} ;
Original file line number Diff line number Diff line change 11import { firebaseDatabase } from "@/config" ;
22import { User } from "@/context/Auth/types" ;
33import { MessageSnapshotResponse } from "@/context/Chat/types" ;
4+ import { DB_NAME } from "@/utils" ;
45import {
56 child ,
67 get ,
@@ -13,7 +14,7 @@ import {
1314} from "firebase/database" ;
1415
1516export const addUserInfo = async ( user : User ) => {
16- const collectionRef = ref ( firebaseDatabase , "usersTable" ) ;
17+ const collectionRef = ref ( firebaseDatabase , DB_NAME . USER_TABLE ) ;
1718 const snapshot = await child ( collectionRef , user . uid ) ;
1819 if ( ! snapshot . key ) {
1920 set ( snapshot , user ) ;
@@ -33,7 +34,7 @@ const fetchMessages = async (
3334
3435export const fetchCommonRoomMessages =
3536 async ( ) : Promise < MessageSnapshotResponse > => {
36- const collectionRef = ref ( firebaseDatabase , "chatRoom" ) ;
37+ const collectionRef = ref ( firebaseDatabase , DB_NAME . CHAT_ROOM ) ;
3738 // By default the fetch item is sorted by timestamp
3839 return fetchMessages ( collectionRef ) ;
3940 } ;
Original file line number Diff line number Diff line change 11export const dateFormatter = new Intl . DateTimeFormat ( navigator . language , {
2- month : "short" ,
3- day : "numeric" ,
4- year : "numeric" ,
5- hour : "numeric" ,
6- minute : "2-digit" ,
2+ month : "short" ,
3+ day : "numeric" ,
4+ year : "numeric" ,
5+ hour : "numeric" ,
6+ minute : "2-digit" ,
7+ } ) ;
8+
9+ export const dateFormatterShort = new Intl . DateTimeFormat ( navigator . language , {
10+ month : "short" ,
11+ day : "numeric" ,
12+ year : "numeric" ,
713} ) ;
814
915export const numberFormatter = new Intl . NumberFormat ( navigator . language , {
10- notation : "compact" ,
11- } ) ;
16+ notation : "compact" ,
17+ } ) ;
18+
19+ export const DB_NAME : { [ key : string ] : string } = {
20+ USER_TABLE : "usersTable" ,
21+ CHAT_ROOM : "chatRoom" ,
22+ } ;
You can’t perform that action at this time.
0 commit comments