Skip to content

Commit 62ab0f3

Browse files
committed
DB name on utils file
1 parent 2739a90 commit 62ab0f3

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

src/context/Auth/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export type User = {
44
profile_picture: string;
55
userName: string;
66
uid: string;
7+
createdAt: number;
78
}
89

910
export type AuthState = {

src/context/Chat/chatReducer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import { DB_NAME } from "@/utils";
12
import { ACTION_TYPE, ChatState } from "./types";
23

34
export const initialState: ChatState = {
45
userList: {},
56
isLoading: false,
6-
chatRoomId: "chatRoom",
7+
chatRoomId: DB_NAME.CHAT_ROOM,
78
oneToOneRoomId: "",
89
};
910

src/context/Chat/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type MessageSnapshotResponse = {
1515
export 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 = {
3838
type 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
};

src/services/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { firebaseDatabase } from "@/config";
22
import { User } from "@/context/Auth/types";
33
import { MessageSnapshotResponse } from "@/context/Chat/types";
4+
import { DB_NAME } from "@/utils";
45
import {
56
child,
67
get,
@@ -13,7 +14,7 @@ import {
1314
} from "firebase/database";
1415

1516
export 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

3435
export 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
};

src/utils/index.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
export 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

915
export 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+
};

0 commit comments

Comments
 (0)