-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add network request example with layered architecture #279
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
Merged
+506
−92
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f48e677
feat(api): implement external API mock handlers and update routing
bogy0 6df9fea
refactor(server): extract server configuration to a separate module
bogy0 65bbac4
feat(nav, dashboard): enhance navigation and dashboard with dynamic r…
bogy0 537d382
fix: query param typo fix
bogy0 927aa75
fix: sentence case fixes and some pollishing
bogy0 fd132f6
fix: update post title in externalHandlers
bogy0 e037b45
feat: fix preview:prod
lee-chase 9a3fb40
feat: enhance PostComponent to accept dynamic postId prop
bogy0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /** | ||
| * Copyright IBM Corp. 2025 | ||
| * | ||
| * This source code is licensed under the Apache-2.0 license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| // Server configuration constants | ||
| // Extracted to avoid importing the full server during tests | ||
| export const port = process.env.PORT || 5173; | ||
| export const base = process.env.BASE || 'http://localhost'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { getComments, getPost } from '../../../api/message.js'; | ||
| import { Heading, Section, Tile, Stack, Layer } from '@carbon/react'; | ||
| import { useEffect, useState } from 'react'; | ||
|
|
||
| const PostComponent = () => { | ||
| const [post, setPost] = useState(); | ||
| const [comments, setComments] = useState([]); | ||
|
|
||
| const loadPost = async () => { | ||
| try { | ||
| const post = await getPost(1); | ||
| setPost(post); | ||
| } catch { | ||
| setPost('Failed to load message'); | ||
| } | ||
| }; | ||
|
|
||
| const loadComments = async () => { | ||
| try { | ||
| const comments = await getComments(1); | ||
| setComments(comments); | ||
| } catch { | ||
| setComments([]); | ||
| } | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| const loadData = async () => { | ||
| await loadPost(); | ||
| await loadComments(); | ||
| }; | ||
| loadData(); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <Section as="article" level={3}> | ||
| <Heading>Posts</Heading> | ||
| <Tile> | ||
| <Stack gap={6}> | ||
| <Section as="article" level={3}> | ||
| <Section level={4}> | ||
| <Heading>{post?.title ?? 'Loading...'}</Heading> | ||
| <p>{post?.body}</p> | ||
| </Section> | ||
| </Section> | ||
|
|
||
| <Section as="article" level={5}> | ||
| <Stack gap={3}> | ||
| <Heading>Comments</Heading> | ||
| <Section as="article" level={6}> | ||
| <Stack gap={3}> | ||
| {Array.isArray(comments) && | ||
| comments.map((comment) => ( | ||
| <Layer key={comment.id}> | ||
| <Tile title={`Post from ${comment.email}`}> | ||
| <Heading>{`From ${comment.email}`}</Heading> | ||
| <p>{comment.body}</p> | ||
| </Tile> | ||
| </Layer> | ||
| ))} | ||
| </Stack> | ||
| </Section> | ||
| </Stack> | ||
| </Section> | ||
| </Stack> | ||
| </Tile> | ||
| </Section> | ||
| ); | ||
| }; | ||
|
|
||
| export default PostComponent; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.