init commit,
This commit is contained in:
373
03_source/mobile_notworking.del/src/store/ChatStore.js
Normal file
373
03_source/mobile_notworking.del/src/store/ChatStore.js
Normal file
@@ -0,0 +1,373 @@
|
||||
import { Store } from 'pullstate';
|
||||
|
||||
const ChatStore = new Store({
|
||||
chats: [
|
||||
{
|
||||
id: 1,
|
||||
contact_id: 1,
|
||||
chats: [
|
||||
{
|
||||
id: 1,
|
||||
preview: 'This is a test whatsapp message inside the whatsapp clone app',
|
||||
received: true,
|
||||
sent: false,
|
||||
date: '20:05',
|
||||
read: false,
|
||||
starred: false,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
preview: 'This is a test whatsapp message inside the whatsapp clone app',
|
||||
received: false,
|
||||
sent: true,
|
||||
date: '20:05',
|
||||
read: false,
|
||||
starred: false,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
preview: 'This is a test whatsapp message inside the whatsapp clone app',
|
||||
received: true,
|
||||
sent: false,
|
||||
date: '20:05',
|
||||
read: false,
|
||||
starred: false,
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
preview: 'This is a test whatsapp message inside the whatsapp clone app',
|
||||
received: false,
|
||||
sent: true,
|
||||
date: '20:05',
|
||||
read: false,
|
||||
starred: false,
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
preview: 'This is a test whatsapp message inside the whatsapp clone app',
|
||||
received: true,
|
||||
sent: false,
|
||||
date: '20:05',
|
||||
read: false,
|
||||
starred: false,
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
preview: 'This is a test whatsapp message inside the whatsapp clone app',
|
||||
received: false,
|
||||
sent: true,
|
||||
date: '20:05',
|
||||
read: false,
|
||||
starred: false,
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
preview: 'This is a test whatsapp message inside the whatsapp clone app',
|
||||
received: true,
|
||||
sent: false,
|
||||
date: '20:05',
|
||||
read: false,
|
||||
starred: false,
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
preview: 'This is a test whatsapp message inside the whatsapp clone app',
|
||||
received: false,
|
||||
sent: true,
|
||||
date: '20:05',
|
||||
read: false,
|
||||
starred: false,
|
||||
},
|
||||
{
|
||||
id: 9,
|
||||
preview: 'This is a test whatsapp message inside the whatsapp clone app',
|
||||
received: true,
|
||||
sent: false,
|
||||
date: '20:05',
|
||||
read: false,
|
||||
starred: false,
|
||||
},
|
||||
{
|
||||
id: 10,
|
||||
preview: 'This is a test whatsapp message inside the whatsapp clone app',
|
||||
received: false,
|
||||
sent: true,
|
||||
date: '20:05',
|
||||
read: false,
|
||||
starred: false,
|
||||
},
|
||||
{
|
||||
id: 11,
|
||||
preview: 'This is a test whatsapp message inside the whatsapp clone app',
|
||||
received: true,
|
||||
sent: false,
|
||||
date: '20:05',
|
||||
read: false,
|
||||
starred: false,
|
||||
},
|
||||
{
|
||||
id: 12,
|
||||
preview: 'This is a test whatsapp message inside the whatsapp clone app',
|
||||
received: false,
|
||||
sent: true,
|
||||
date: '20:05',
|
||||
read: false,
|
||||
starred: false,
|
||||
},
|
||||
{
|
||||
id: 13,
|
||||
preview: 'This is a test whatsapp message inside the whatsapp clone app',
|
||||
received: true,
|
||||
sent: false,
|
||||
date: '20:05',
|
||||
read: false,
|
||||
starred: false,
|
||||
},
|
||||
{
|
||||
id: 14,
|
||||
preview: 'This is a test whatsapp message inside the whatsapp clone app',
|
||||
received: false,
|
||||
sent: true,
|
||||
date: '20:10',
|
||||
read: false,
|
||||
starred: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
contact_id: 2,
|
||||
chats: [
|
||||
{
|
||||
id: 1,
|
||||
preview: "Excited for the Ioniconf 2021! The 23rd can't come quick enough",
|
||||
received: false,
|
||||
sent: true,
|
||||
date: 'Yesterday',
|
||||
read: true,
|
||||
starred: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
contact_id: 3,
|
||||
chats: [
|
||||
{
|
||||
id: 1,
|
||||
preview: "Excited for the Ioniconf 2021! The 23rd can't come quick enough",
|
||||
received: false,
|
||||
sent: true,
|
||||
date: 'Saturday',
|
||||
read: true,
|
||||
starred: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
contact_id: 4,
|
||||
chats: [
|
||||
{
|
||||
id: 1,
|
||||
preview: 'Hey Alan, this is a test whatsapp message',
|
||||
received: true,
|
||||
sent: false,
|
||||
date: 'Friday',
|
||||
read: false,
|
||||
starred: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
contact_id: 5,
|
||||
chats: [
|
||||
{
|
||||
id: 1,
|
||||
preview: 'Hey Alan, this is a test whatsapp message',
|
||||
received: true,
|
||||
sent: false,
|
||||
date: 'Thursday',
|
||||
read: false,
|
||||
starred: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
contact_id: 6,
|
||||
chats: [
|
||||
{
|
||||
id: 1,
|
||||
preview: 'Hey Alan, this is a test received whatsapp message',
|
||||
received: true,
|
||||
sent: false,
|
||||
date: 'Wednesday',
|
||||
read: false,
|
||||
starred: false,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
preview: 'Hey Josh, this is a test sent whatsapp message',
|
||||
received: true,
|
||||
sent: true,
|
||||
date: 'Wednesday',
|
||||
read: true,
|
||||
starred: false,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
preview: 'Awesome man! This seems to be coming together OK!',
|
||||
received: true,
|
||||
sent: false,
|
||||
date: 'Wednesday',
|
||||
read: true,
|
||||
starred: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
contact_id: 7,
|
||||
chats: [
|
||||
{
|
||||
id: 1,
|
||||
preview: 'Goodluck on the quest to space, the moon and mars!',
|
||||
received: true,
|
||||
sent: false,
|
||||
date: '08/06/2021',
|
||||
read: true,
|
||||
starred: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
contact_id: 8,
|
||||
chats: [
|
||||
{
|
||||
id: 1,
|
||||
preview: 'Hey Bill, This is a test sent message to your whatsapp',
|
||||
received: true,
|
||||
sent: false,
|
||||
date: '05/06/2021',
|
||||
read: true,
|
||||
starred: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 9,
|
||||
contact_id: 10,
|
||||
chats: [
|
||||
{
|
||||
id: 1,
|
||||
preview:
|
||||
'This is Alans WhatsApp clone using the Ionic Framework and CapacitorJS for some native functionality.',
|
||||
received: true,
|
||||
sent: false,
|
||||
date: 'Wednesday',
|
||||
read: false,
|
||||
starred: false,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
preview:
|
||||
"Yep, and don't forget the Ionic Animations for the slick UI transitions you see, and some Ionic Gestures for sliding etc, as well as some other things!",
|
||||
received: true,
|
||||
sent: true,
|
||||
date: 'Wednesday',
|
||||
read: true,
|
||||
starred: false,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
preview: 'Cool! It looks good, can we get another teaser?',
|
||||
received: true,
|
||||
sent: false,
|
||||
date: 'Wednesday',
|
||||
read: true,
|
||||
starred: false,
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
preview: "Sure... I'll post one on Twitter now!",
|
||||
received: false,
|
||||
sent: true,
|
||||
date: 'Wednesday',
|
||||
read: true,
|
||||
starred: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
export const getNotificationCount = allChats => {
|
||||
let notificationCount = 0;
|
||||
|
||||
allChats.forEach(chats => {
|
||||
chats.chats.forEach(chat => {
|
||||
if (!chat.read) {
|
||||
notificationCount++;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return notificationCount;
|
||||
};
|
||||
|
||||
export const markAllAsRead = contactId => {
|
||||
ChatStore.update(s => {
|
||||
const chatIndex = s.chats.findIndex(chat => chat.contact_id === parseInt(contactId));
|
||||
|
||||
s.chats[chatIndex].chats.forEach(chat => {
|
||||
chat.read = true;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const sendChatMessage = (
|
||||
contactId,
|
||||
message,
|
||||
reply = false,
|
||||
replyID = false,
|
||||
image = false,
|
||||
imagePath = false,
|
||||
) => {
|
||||
const today = new Date();
|
||||
const currentTime = `${today.getHours() < 10 ? `0${today.getHours()}` : today.getHours()}:${
|
||||
today.getMinutes() < 10 ? `0${today.getMinutes()}` : today.getMinutes()
|
||||
}`;
|
||||
|
||||
ChatStore.update(s => {
|
||||
const chatIndex = s.chats.findIndex(chat => chat.contact_id === parseInt(contactId));
|
||||
const newChat = {
|
||||
id: s.chats[chatIndex].length + 1,
|
||||
preview: message,
|
||||
received: false,
|
||||
sent: true,
|
||||
date: currentTime,
|
||||
read: true,
|
||||
starred: false,
|
||||
reply,
|
||||
replyID,
|
||||
image: image,
|
||||
imagePath: imagePath,
|
||||
};
|
||||
|
||||
s.chats[chatIndex].chats.push(newChat);
|
||||
});
|
||||
};
|
||||
|
||||
export const starChatMessage = (contactId, messageId) => {
|
||||
ChatStore.update(s => {
|
||||
const chatIndex = s.chats.findIndex(chat => chat.contact_id === parseInt(contactId));
|
||||
const messageIndex = s.chats[chatIndex].chats.findIndex(message => message.id === parseInt(messageId));
|
||||
|
||||
s.chats[chatIndex].chats[messageIndex].starred = !s.chats[chatIndex].chats[messageIndex].starred;
|
||||
});
|
||||
};
|
||||
|
||||
export default ChatStore;
|
113
03_source/mobile_notworking.del/src/store/ContactStore.js
Normal file
113
03_source/mobile_notworking.del/src/store/ContactStore.js
Normal file
@@ -0,0 +1,113 @@
|
||||
import { Store } from 'pullstate';
|
||||
|
||||
const ContactStore_long = new Store({
|
||||
contacts: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Amy Sister',
|
||||
avatar: '/assets/amy.jpeg',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Max Lynch',
|
||||
avatar: '/assets/max.jpeg',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'Mike Hartington',
|
||||
avatar: '/assets/mike.jpeg',
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: 'Henk Jurriens',
|
||||
avatar: '/assets/henk.jpeg',
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
name: 'Simon Grimm',
|
||||
avatar: '/assets/simon.jpeg',
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
name: 'Josh Morony',
|
||||
avatar: '/assets/josh.jpeg',
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
name: 'Elon Musk',
|
||||
avatar: '/assets/elon.jpeg',
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
name: 'Bill Gates',
|
||||
avatar: '/assets/bill.jpeg',
|
||||
},
|
||||
{
|
||||
id: 9,
|
||||
name: 'Mark Zuckerberg',
|
||||
avatar: '/assets/mark.jpeg',
|
||||
},
|
||||
{
|
||||
id: 10,
|
||||
name: 'Ionic Framework (not)',
|
||||
avatar: '/assets/ionic.png',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const ContactStore = new Store({
|
||||
contacts: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Amy Sister',
|
||||
avatar: '/assets/amy.jpeg',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Max Lynch',
|
||||
avatar: '/assets/max.jpeg',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'Mike Hartington',
|
||||
avatar: '/assets/mike.jpeg',
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: 'Henk Jurriens',
|
||||
avatar: '/assets/henk.jpeg',
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
name: 'Simon Grimm',
|
||||
avatar: '/assets/simon.jpeg',
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
name: 'Josh Morony',
|
||||
avatar: '/assets/josh.jpeg',
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
name: 'Elon Musk',
|
||||
avatar: '/assets/elon.jpeg',
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
name: 'Bill Gates',
|
||||
avatar: '/assets/bill.jpeg',
|
||||
},
|
||||
{
|
||||
id: 9,
|
||||
name: 'Mark Zuckerberg',
|
||||
avatar: '/assets/mark.jpeg',
|
||||
},
|
||||
{
|
||||
id: 10,
|
||||
name: 'Ionic Framework (not)',
|
||||
avatar: '/assets/ionic.png',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
export default ContactStore;
|
20
03_source/mobile_notworking.del/src/store/Selectors.js
Normal file
20
03_source/mobile_notworking.del/src/store/Selectors.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import { createSelector } from 'reselect';
|
||||
|
||||
const getState = state => state;
|
||||
|
||||
// General getters
|
||||
export const getContacts = createSelector(getState, state => state.contacts);
|
||||
export const getChats = createSelector(getState, state => state.chats);
|
||||
|
||||
// More specific getters
|
||||
export const getChat = contactId =>
|
||||
createSelector(getState, state => state.chats.filter(c => parseInt(c.contact_id) === parseInt(contactId))[0].chats);
|
||||
export const getContact = contactId =>
|
||||
createSelector(getState, state => state.contacts.filter(c => parseInt(c.id) === parseInt(contactId))[0]);
|
||||
|
||||
export const getChatNotificationCount = contactId =>
|
||||
createSelector(getState, state =>
|
||||
state.chats
|
||||
.filter(c => parseInt(c.contact_id) === parseInt(contactId))[0]
|
||||
.chats.filter(chat => chat.read === false),
|
||||
);
|
2
03_source/mobile_notworking.del/src/store/index.js
Normal file
2
03_source/mobile_notworking.del/src/store/index.js
Normal file
@@ -0,0 +1,2 @@
|
||||
export { default as ChatStore } from './ChatStore';
|
||||
export { default as ContactStore } from './ContactStore';
|
Reference in New Issue
Block a user