English
Checkpoint
What must work
Run in Source/Chatex.Web:
powershell
npm run buildpowershell
npm test -- --watch=falsepowershell
npm run lintpowershell
npm run format:checkCompare the finished files with the reference:
powershell
git diff --no-index --stat Source/Chatex.Web/src/app/shared D:\Work\Chatex-Reference\Source\Chatex.Web\src\app\sharedpowershell
git diff --no-index --stat Source/Chatex.Web/src/app/features/new-chat D:\Work\Chatex-Reference\Source\Chatex.Web\src\app\features\new-chatBoth print nothing; the same holds for core/media, features/discover and no-chat.page.ts. The store, its spec, the list pane, the shell and the routes grow in topics 19–21.
Commit:
powershell
git add .powershell
git commit -m "Add the chat store, avatars, the chat list, new chats and the discover page"Common mistakes
Table 18.1. Common mistakes in the chat list
| Symptom | Cause | Fix |
|---|---|---|
NG8004: No pipe found with name 'shortWhen'. | ShortWhenPipe is missing in the component's imports | import the pipe class |
TS2339: Property 'update' does not exist on type 'InputSignal<UserSummaryDto[]>'. | selected declared with input(), which is read-only, instead of model() | use model() for two-way inputs |
| a new chat appears in the list only after a reload | the code mutates the array (items().unshift(...)) instead of setting a new one | always update((list) => [item, ...list]) |
avatars show as broken images, and the Network tab shows 401 for /api/users/…/avatar | the image URL was put into <img src> directly, which sends no bearer token | load it through BlobUrlService and bind the blob URL |
| after signing in as another user, the previous user's chats flash for a moment | the store or the blob cache is not reset on sign-out | read auth.sessionEpoch() in an effect and reset |
| search results jump back to an older query | mergeMap (or a plain subscribe per keystroke) instead of switchMap | switchMap cancels the outdated request |
Self-check questions
- Why do the stores exist? What would go wrong if every component loaded its own chats?
- Why does
ChatsStorekeepdetailsseparately fromitems? Which DTO goes where? - What does
setDetailsdo with a chat whosemyRoleis null, and why? - Why is
removedaSubjectand not a signal? - Why can an
<img>not load an avatar from the API directly? How doesBlobUrlServicesolve it, and what does the CSP have to allow? - Why does
BlobUrlServicecache promises rather than URLs? - What does
resource()do? How does a changed avatar get reloaded? - Which problems do
debounceTime,distinctUntilChangedandswitchMapsolve in the user search? - What is the difference between
input(),output()andmodel()? - How does the list pane load the next page without listening to scroll events?
Exercises
- Sort by unread. Add a toggle to the list pane that shows chats with unread messages first. Do it with a
computedoverstore.items()and a local signal; do not change the store. - Avatar tooltip. Give
Avataran optional inputtitleand show it as the native tooltip of the image and of the initials. Use it in the chat list. - Store test. Write a test for
loadMore: the first page returnsnextCursor: 'c1', the second page contains one new chat and one already known chat. Expect three chats, the API to be called with'c1', andhasMore()to be false.