-
install recoil
npm install recoil
-
src/recoil.js
import { atom } from "recoil";
export const selectedUserState = atom({
key: "selectedUser",
default: null,
});
-
src/pages/Main/Message/index.js
setTimeout(() => {
const cb = document.getElementById("chat-content").parentElement;
if (cb) {
cb.scrollTop = cb.scrollHeight;
}
}, 200);
-
updated query (src/pages/Main/Message/index.js)
subscription MyQuery($where: messages_bool_exp = {}) {
messages(where: $where, order_by: { createdAt: asc }) {
id
fromUserId
message
fromUser {
name
picture
}
createdAt
}
}
-
update variable params (src/pages/Main/Message/index.js)
let params = { where: {} };
if (selectedUser && !selectedUser.id) {
params.where = {
toUserId: {
_is_null: true,
},
};
} else if (selectedUser && selectedUser.id) {
params.where = {
_or: [
{
fromUserId: {
_eq: user.sub,
},
toUserId: {
_eq: selectedUser.id,
},
},
{
fromUserId: {
_eq: selectedUser.id,
},
toUserId: {
_eq: user.sub,
},
},
],
};
}
-
update query untuk contact list (src/pages/Main/Contact/index.js)
query MyQuery(
$order_by: [users_order_by!] = { name: desc }
$_neq: String = ""
) {
users(order_by: $order_by, where: { id: { _neq: $_neq } }) {
id
name
picture
}
}
-
install env-cmd & update package.json
npm install env-cmd
"build:prod": "env-cmd -f .env.prod npm run-script build"
Komentar
Posting Komentar