-
Notifications
You must be signed in to change notification settings - Fork 0
Add Update section to Settings page as toast fallback #18
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d121827
Initial plan
Copilot 0ebff8b
Add Update section to Settings page with useAppUpdateAvailable refactor
Copilot 27140e6
Extract SettingsSection wrapper component to consolidate repeating se…
Copilot 5b5a77b
Extract section body components; fix storage null checks with != null…
Copilot 2e220be
Hook dontToast param; self-contained UpdateSectionBody; always-visibl…
Copilot feec08c
Drop window refs, replace alert with persistent toast, use Button com…
Copilot 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,20 @@ | ||
| import { Icon } from '../../components/Icon'; | ||
|
|
||
| export function AboutSectionBody() { | ||
| return ( | ||
| <> | ||
| <div className="flex items-center gap-3 mb-3"> | ||
| <div className="p-2 bg-primary/10 rounded-lg"> | ||
| <Icon name="zap" size="md" className="text-primary" /> | ||
| </div> | ||
| <div> | ||
| <p className="text-base font-semibold text-body">EV Charge Tracker</p> | ||
| <p className="text-sm text-body-secondary">Version 1.0.0</p> | ||
| </div> | ||
| </div> | ||
| <p className="text-sm text-body-secondary"> | ||
| Track your electric vehicle charging sessions, costs, and usage across all your locations. | ||
| </p> | ||
| </> | ||
| ); | ||
| } |
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,67 @@ | ||
| import { useEffect, useState } from 'react'; | ||
| import { useNavigate } from 'react-router-dom'; | ||
| import type { Location } from '../../data/data-types'; | ||
| import { useLocations } from '../../hooks/useLocations'; | ||
| import { useToast } from '../../hooks/useToast'; | ||
| import { ItemListButton } from '../../components/ItemListButton'; | ||
| import { EmptyState } from '../../components/EmptyState'; | ||
| import { LocationItem } from './LocationItem'; | ||
|
|
||
| export function LocationsSectionBody() { | ||
| const navigate = useNavigate(); | ||
| const { getLocationList, deleteLocation } = useLocations(); | ||
| const { showToast } = useToast(); | ||
| const [locations, setLocations] = useState<Location[]>([]); | ||
|
|
||
| useEffect(() => { | ||
| const loadLocations = async () => { | ||
| const result = await getLocationList(); | ||
|
|
||
| if (result.success) { | ||
| setLocations(result.data); | ||
| } | ||
| }; | ||
|
|
||
| loadLocations(); | ||
| }, [getLocationList]); | ||
|
|
||
| const handleDelete = async (id: string) => { | ||
| const confirmed = confirm('Are you sure you want to delete this location?'); | ||
|
|
||
| if (!confirmed) { | ||
| return; | ||
| } | ||
|
|
||
| const result = await deleteLocation(id); | ||
|
|
||
| if (!result.success) { | ||
| showToast({ message: `Failed to delete location: ${result.error}`, variant: 'error', persistent: true }); | ||
| return; | ||
| } | ||
|
|
||
| setLocations((prev) => prev.filter((l) => l.id !== id)); | ||
| }; | ||
|
|
||
| return locations.length === 0 ? ( | ||
| <EmptyState | ||
| icon="map-pin" | ||
| title="No locations yet" | ||
| message="Add a location to track where you charge." | ||
| actionLabel="Add Location" | ||
| onAction={() => navigate('/settings/locations/add')} | ||
| /> | ||
| ) : ( | ||
| <div> | ||
| <ItemListButton | ||
| label="Add location" | ||
| onClick={() => navigate('/settings/locations/add')} | ||
| className="mb-3" | ||
| /> | ||
| <div className="space-y-3"> | ||
| {locations.map((location) => ( | ||
| <LocationItem key={location.id} location={location} onDelete={handleDelete} /> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
|
vanister marked this conversation as resolved.
vanister marked this conversation as resolved.
|
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,20 @@ | ||
| import { clsx } from 'clsx'; | ||
| import type { ReactNode } from 'react'; | ||
| import { SectionHeader } from '../../components/SectionHeader'; | ||
|
|
||
| type SettingsSectionProps = { | ||
| title: string; | ||
| children: ReactNode; | ||
| cardClassName?: string; | ||
| }; | ||
|
|
||
| export function SettingsSection({ title, children, cardClassName }: SettingsSectionProps) { | ||
| return ( | ||
| <section> | ||
| <SectionHeader title={title} /> | ||
| <div className={clsx('p-4 bg-surface border border-default rounded-lg', cardClassName)}> | ||
| {children} | ||
| </div> | ||
| </section> | ||
| ); | ||
| } |
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,57 @@ | ||
| import { useEffect } from 'react'; | ||
| import { useImmerState } from '../../hooks/useImmerState'; | ||
| import { formatBytes } from '../../utilities/formatUtils'; | ||
|
|
||
| type StorageState = { | ||
| storageUsed: number | null; | ||
| storageQuota: number | null; | ||
| }; | ||
|
|
||
| const DEFAULT_STATE: StorageState = { | ||
| storageUsed: null, | ||
| storageQuota: null | ||
| }; | ||
|
|
||
| export function StorageSectionBody() { | ||
| const [state, setState] = useImmerState<StorageState>(DEFAULT_STATE); | ||
|
|
||
| useEffect(() => { | ||
| const loadStorageEstimate = async () => { | ||
| const estimate = await navigator.storage?.estimate?.(); | ||
| setState((draft) => { | ||
| draft.storageUsed = estimate?.usage ?? null; | ||
| draft.storageQuota = estimate?.quota ?? null; | ||
| }); | ||
| }; | ||
|
|
||
| loadStorageEstimate(); | ||
| }, [setState]); | ||
|
|
||
| if (state.storageUsed == null || state.storageQuota == null) { | ||
| return <p className="text-sm text-body-secondary">Storage information unavailable</p>; | ||
| } | ||
|
|
||
| const storagePercent = | ||
| state.storageQuota > 0 | ||
| ? Math.min(100, (state.storageUsed / state.storageQuota) * 100) | ||
| : null; | ||
|
|
||
| return ( | ||
| <> | ||
| <div className="flex items-center justify-between text-sm"> | ||
| <span className="text-body-secondary">Used</span> | ||
| <span className="text-body font-medium"> | ||
| {formatBytes(state.storageUsed)} of {formatBytes(state.storageQuota)} | ||
| </span> | ||
| </div> | ||
| {storagePercent != null && ( | ||
| <div className="h-2 bg-border rounded-full overflow-hidden"> | ||
| <div | ||
| className="h-full bg-primary rounded-full transition-all" | ||
| style={{ width: `${storagePercent}%` }} | ||
| /> | ||
| </div> | ||
| )} | ||
| </> | ||
| ); | ||
| } |
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.