Hone logo
Hone
Problems

Building a Responsive and Adaptive Angular Application

This challenge focuses on creating an Angular application that provides an optimal user experience across a wide range of devices, from large desktops to small mobile phones. You will implement responsive design principles and adapt UI elements to best suit the user's screen size and interaction capabilities, making your application truly universal.

Problem Description

Your task is to build a single-page Angular application that dynamically adjusts its layout and presentation based on the device's screen size. The application should present a list of "items," and the way these items are displayed should change significantly between desktop and mobile views.

Key Requirements:

  1. Responsive Layout: Implement a layout that adapts using CSS media queries or a responsive framework (e.g., Bootstrap, Angular Material).
  2. Item Display Adaptation:
    • Desktop View: Display items in a multi-column grid (e.g., 3 or 4 columns). Each item should show a title, a brief description, and a "Read More" button.
    • Mobile View: Display items in a single-column list. Each item should show only the title and a "View Details" button.
  3. Data Fetching (Mock): For simplicity, the application should use mock data for the list of items. You can define this data directly within a service or component.
  4. Navigation:
    • On desktop, clicking "Read More" should navigate to a separate "Details" page for that item, passing the item's ID.
    • On mobile, clicking "View Details" should either expand the item to show more details inline or navigate to a "Details" page. For this challenge, let's assume inline expansion for mobile.
  5. Angular Project Structure: Utilize standard Angular project structure, including components, services, and routing.

Expected Behavior:

  • When the browser window is wide (e.g., > 768px), the items should appear in a grid layout.
  • When the browser window is narrow (e.g., < 768px), the items should appear as a single-column list.
  • On desktop, clicking "Read More" transitions to a dedicated item detail view.
  • On mobile, clicking "View Details" toggles the visibility of additional item information (description, etc.) within the list item itself.

Edge Cases:

  • Window Resizing: The layout and display should update smoothly as the browser window is resized without requiring a page refresh.
  • No Items: The application should gracefully handle scenarios where there are no items to display (e.g., show a "No items found" message).

Examples

Example 1: Desktop View

Input:
- Screen width > 768px
- Mock data:
  - Item 1: { id: 1, title: "Angular Fundamentals", description: "Learn the core concepts of Angular development." }
  - Item 2: { id: 2, title: "Reactive Programming", description: "Master RxJS for efficient data handling." }
  - Item 3: { id: 3, title: "State Management", description: "Explore various state management patterns." }

Output (Conceptual):
[
  [Item 1 Title, Item 1 Description, "Read More" Button],
  [Item 2 Title, Item 2 Description, "Read More" Button],
  [Item 3 Title, Item 3 Description, "Read More" Button]
]

Explanation: On a desktop, items are displayed in a grid. Clicking "Read More" for Item 1 would navigate to /items/1.

Example 2: Mobile View

Input:
- Screen width < 768px
- Mock data:
  - Item 1: { id: 1, title: "Angular Fundamentals", description: "Learn the core concepts of Angular development." }
  - Item 2: { id: 2, title: "Reactive Programming", description: "Master RxJS for efficient data handling." }

Output (Conceptual):
[
  [Item 1 Title, "View Details" Button (initially collapsed)],
  [Item 2 Title, "View Details" Button (initially collapsed)]
]

// After clicking "View Details" for Item 1:
[
  [Item 1 Title, Item 1 Description, "View Details" Button (now expanded)],
  [Item 2 Title, "View Details" Button (initially collapsed)]
]

Explanation: On mobile, items are in a list. Clicking "View Details" for Item 1 expands it to show the description inline.

Example 3: Item Detail View (Desktop)

Input:
- Navigated to `/items/1` from desktop view.
- Mock data for Item 1: { id: 1, title: "Angular Fundamentals", description: "Learn the core concepts of Angular development." }

Output (Conceptual):
[
  H1: "Angular Fundamentals"
  Paragraph: "Learn the core concepts of Angular development."
  Button: "Back to List"
]

Explanation: A dedicated page displays the full details of the selected item.

Constraints

  • The application must be built using Angular version 14 or higher.
  • TypeScript must be used for all application logic.
  • The core responsive logic should be implemented without relying solely on pre-built responsive UI frameworks for layout (though they can be used for styling individual components). Focus on demonstrating understanding of responsive principles.
  • The solution should be a single, runnable Angular project.
  • Performance should be reasonable; no significant delays when resizing the window or navigating between views.

Notes

  • Consider using a component to encapsulate the display of a single "item" to promote reusability and maintainability.
  • Angular's BreakpointObserver service can be a powerful tool for detecting screen size changes.
  • For the "Details" page on desktop, you will need to set up Angular routing.
  • Think about how to manage the state of expanded/collapsed items on mobile.
  • The exact breakpoint for switching between desktop and mobile views can be chosen by you, but it should be clearly defined in your CSS.
Loading editor...
typescript