Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: change message interface #40

Merged
merged 42 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4b7da9d
refactor: change message interface
luizmuraro Sep 1, 2024
f23a852
feat: create message avatar component
luizmuraro Sep 2, 2024
5100676
feat: create editable message component
luizmuraro Sep 2, 2024
61709cc
feat: create message actions component
luizmuraro Sep 2, 2024
25ce23b
feat: create message content component
luizmuraro Sep 2, 2024
2b6856b
feat: create message component
luizmuraro Sep 2, 2024
4dc7167
feat: create loading indicator component
luizmuraro Sep 2, 2024
002e698
feat: transform usable function into hooks
luizmuraro Sep 2, 2024
4b89bda
chore: update chat-list component
luizmuraro Sep 2, 2024
9809359
refactor: run rebase
devjoaov Sep 2, 2024
adbf20b
feat: add key press ented on editable messages
luizmuraro Sep 4, 2024
0009f61
feat: show message edit and message action only on hover
luizmuraro Sep 4, 2024
6a3f23b
chore: change hover location
luizmuraro Sep 4, 2024
dd0848d
feat: insert header into App's layout
luizmuraro Sep 4, 2024
f0805d1
chore: add actions hover
luizmuraro Sep 4, 2024
cb74aba
feat: refactor sidebar
luizmuraro Sep 4, 2024
f1f8e45
feat: create message UI
luizmuraro Sep 4, 2024
acc4e5a
chore: make sidebar and main scrollable
luizmuraro Sep 4, 2024
bdd3072
feat: integrate new chat UI
luizmuraro Sep 5, 2024
a112ccd
chore: add hover on sidebar buttons
luizmuraro Sep 6, 2024
d624c18
feat: add empty state
luizmuraro Sep 6, 2024
b90c534
chore: handle user removing the last chat
luizmuraro Sep 6, 2024
1426d29
chore: disable edit button when empty
luizmuraro Sep 6, 2024
7380552
chore: remove scroll bar when it's not needed
luizmuraro Sep 9, 2024
0aa5097
feat: auto select edit content
luizmuraro Sep 9, 2024
bcd633d
feat: create use-mobile store
luizmuraro Sep 10, 2024
94e1341
feat: replace is mobile at chat and adjust sizes and paddings for mobile
luizmuraro Sep 10, 2024
1ff73a5
chore: fix editable text area size and shows edit button on mobile
luizmuraro Sep 10, 2024
d5e3bfc
fix: remove button inside another button
luizmuraro Sep 10, 2024
9aae72c
feat: create chat header and remove global header
luizmuraro Sep 10, 2024
797bb9d
chore: handle remove selected chat
luizmuraro Sep 10, 2024
a9cac12
chore: set full height on chat
luizmuraro Sep 10, 2024
7f69d30
feat: create mobile header
luizmuraro Sep 10, 2024
d515288
feat: create chat-list initial loading
luizmuraro Sep 10, 2024
4957945
chore: remove unnecessary isMobile chcker
luizmuraro Sep 10, 2024
138f04d
chore: fix sidebard paddings
luizmuraro Sep 10, 2024
084bcc1
chore: centralize and use loading indicator at forum
luizmuraro Sep 10, 2024
2834094
fix: centralize chat header title
luizmuraro Sep 10, 2024
a84043d
chore: update sidebar
luizmuraro Sep 11, 2024
f23bdac
feat: create message interface migration
luizmuraro Sep 11, 2024
9c48667
chore: pr fixes and code improvments
luizmuraro Sep 11, 2024
b9c4121
Merge pull request #44 from bleu/luiz/op-236-enhance-chat-list-ux-and-ui
luizmuraro Sep 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 92 additions & 92 deletions www/public/mockServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,128 +8,128 @@
* - Please do NOT serve this file on production.
*/

const PACKAGE_VERSION = "2.3.5";
ribeirojose marked this conversation as resolved.
Show resolved Hide resolved
const INTEGRITY_CHECKSUM = "26357c79639bfa20d64c0efca2a87423";
const IS_MOCKED_RESPONSE = Symbol("isMockedResponse");
const activeClientIds = new Set();
const PACKAGE_VERSION = '2.4.1'
const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423'
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
const activeClientIds = new Set()

self.addEventListener("install", () => {
self.skipWaiting();
});
self.addEventListener('install', function () {
self.skipWaiting()
})

self.addEventListener("activate", (event) => {
event.waitUntil(self.clients.claim());
});
self.addEventListener('activate', function (event) {
event.waitUntil(self.clients.claim())
})

self.addEventListener("message", async (event) => {
const clientId = event.source.id;
self.addEventListener('message', async function (event) {
const clientId = event.source.id

if (!clientId || !self.clients) {
return;
return
}

const client = await self.clients.get(clientId);
const client = await self.clients.get(clientId)

if (!client) {
return;
return
}

const allClients = await self.clients.matchAll({
type: "window",
});
type: 'window',
})

switch (event.data) {
case "KEEPALIVE_REQUEST": {
case 'KEEPALIVE_REQUEST': {
sendToClient(client, {
type: "KEEPALIVE_RESPONSE",
});
break;
type: 'KEEPALIVE_RESPONSE',
})
break
}

case "INTEGRITY_CHECK_REQUEST": {
case 'INTEGRITY_CHECK_REQUEST': {
sendToClient(client, {
type: "INTEGRITY_CHECK_RESPONSE",
type: 'INTEGRITY_CHECK_RESPONSE',
payload: {
packageVersion: PACKAGE_VERSION,
checksum: INTEGRITY_CHECKSUM,
},
});
break;
})
break
}

case "MOCK_ACTIVATE": {
activeClientIds.add(clientId);
case 'MOCK_ACTIVATE': {
activeClientIds.add(clientId)

sendToClient(client, {
type: "MOCKING_ENABLED",
type: 'MOCKING_ENABLED',
payload: true,
});
break;
})
break
}

case "MOCK_DEACTIVATE": {
activeClientIds.delete(clientId);
break;
case 'MOCK_DEACTIVATE': {
activeClientIds.delete(clientId)
break
}

case "CLIENT_CLOSED": {
activeClientIds.delete(clientId);
case 'CLIENT_CLOSED': {
activeClientIds.delete(clientId)

const remainingClients = allClients.filter((client) => {
return client.id !== clientId;
});
return client.id !== clientId
})

// Unregister itself when there are no more clients
if (remainingClients.length === 0) {
self.registration.unregister();
self.registration.unregister()
}

break;
break
}
}
});
})

self.addEventListener("fetch", (event) => {
const { request } = event;
self.addEventListener('fetch', function (event) {
const { request } = event

// Bypass navigation requests.
if (request.mode === "navigate") {
return;
if (request.mode === 'navigate') {
return
}

// Opening the DevTools triggers the "only-if-cached" request
// that cannot be handled by the worker. Bypass such requests.
if (request.cache === "only-if-cached" && request.mode !== "same-origin") {
return;
if (request.cache === 'only-if-cached' && request.mode !== 'same-origin') {
return
}

// Bypass all requests when there are no active clients.
// Prevents the self-unregistered worked from handling requests
// after it's been deleted (still remains active until the next reload).
if (activeClientIds.size === 0) {
return;
return
}

// Generate unique request ID.
const requestId = crypto.randomUUID();
event.respondWith(handleRequest(event, requestId));
});
const requestId = crypto.randomUUID()
event.respondWith(handleRequest(event, requestId))
})

async function handleRequest(event, requestId) {
const client = await resolveMainClient(event);
const response = await getResponse(event, client, requestId);
const client = await resolveMainClient(event)
const response = await getResponse(event, client, requestId)

// Send back the response clone for the "response:*" life-cycle events.
// Ensure MSW is active and ready to handle the message, otherwise
// this message will pend indefinitely.
if (client && activeClientIds.has(client.id)) {
(async () => {
const responseClone = response.clone();
;(async function () {
const responseClone = response.clone()

sendToClient(
client,
{
type: "RESPONSE",
type: 'RESPONSE',
payload: {
requestId,
isMockedResponse: IS_MOCKED_RESPONSE in response,
Expand All @@ -141,77 +141,77 @@ async function handleRequest(event, requestId) {
},
},
[responseClone.body],
);
})();
)
})()
}

return response;
return response
}

// Resolve the main client for the given event.
// Client that issues a request doesn't necessarily equal the client
// that registered the worker. It's with the latter the worker should
// communicate with during the response resolving phase.
async function resolveMainClient(event) {
const client = await self.clients.get(event.clientId);
const client = await self.clients.get(event.clientId)

if (client?.frameType === "top-level") {
return client;
if (client?.frameType === 'top-level') {
return client
}

const allClients = await self.clients.matchAll({
type: "window",
});
type: 'window',
})

return allClients
.filter((client) => {
// Get only those clients that are currently visible.
return client.visibilityState === "visible";
return client.visibilityState === 'visible'
})
.find((client) => {
// Find the client ID that's recorded in the
// set of clients that have registered the worker.
return activeClientIds.has(client.id);
});
return activeClientIds.has(client.id)
})
}

async function getResponse(event, client, requestId) {
const { request } = event;
const { request } = event

// Clone the request because it might've been already used
// (i.e. its body has been read and sent to the client).
const requestClone = request.clone();
const requestClone = request.clone()

function passthrough() {
const headers = Object.fromEntries(requestClone.headers.entries());
const headers = Object.fromEntries(requestClone.headers.entries())

// Remove internal MSW request header so the passthrough request
// complies with any potential CORS preflight checks on the server.
// Some servers forbid unknown request headers.
headers["x-msw-intention"] = undefined;
delete headers['x-msw-intention']

return fetch(requestClone, { headers });
return fetch(requestClone, { headers })
}

// Bypass mocking when the client is not active.
if (!client) {
return passthrough();
return passthrough()
}

// Bypass initial page load requests (i.e. static assets).
// The absence of the immediate/parent client in the map of the active clients
// means that MSW hasn't dispatched the "MOCK_ACTIVATE" event yet
// and is not ready to handle requests.
if (!activeClientIds.has(client.id)) {
return passthrough();
return passthrough()
}

// Notify the client that a request has been intercepted.
const requestBuffer = await request.arrayBuffer();
const requestBuffer = await request.arrayBuffer()
const clientMessage = await sendToClient(
client,
{
type: "REQUEST",
type: 'REQUEST',
payload: {
id: requestId,
url: request.url,
Expand All @@ -230,38 +230,38 @@ async function getResponse(event, client, requestId) {
},
},
[requestBuffer],
);
)

switch (clientMessage.type) {
case "MOCK_RESPONSE": {
return respondWithMock(clientMessage.data);
case 'MOCK_RESPONSE': {
return respondWithMock(clientMessage.data)
}

case "PASSTHROUGH": {
return passthrough();
case 'PASSTHROUGH': {
return passthrough()
}
}

return passthrough();
return passthrough()
}

function sendToClient(client, message, transferrables = []) {
return new Promise((resolve, reject) => {
const channel = new MessageChannel();
const channel = new MessageChannel()

channel.port1.onmessage = (event) => {
if (event.data?.error) {
return reject(event.data.error);
if (event.data && event.data.error) {
return reject(event.data.error)
}

resolve(event.data);
};
resolve(event.data)
}

client.postMessage(
message,
[channel.port2].concat(transferrables.filter(Boolean)),
);
});
)
})
}

async function respondWithMock(response) {
Expand All @@ -270,15 +270,15 @@ async function respondWithMock(response) {
// instance will have status code set to 0. Since it's not possible to create
// a Response instance with status code 0, handle that use-case separately.
if (response.status === 0) {
return Response.error();
return Response.error()
}

const mockedResponse = new Response(response.body, response);
const mockedResponse = new Response(response.body, response)

Reflect.defineProperty(mockedResponse, IS_MOCKED_RESPONSE, {
value: true,
enumerable: true,
});
})

return mockedResponse;
return mockedResponse
}
Loading