-
-
Notifications
You must be signed in to change notification settings - Fork 38
Implement GitHub API caching with TTL #50
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,159 @@ | ||
| #root { | ||
| max-width: 1280px; | ||
| margin: 0 auto; | ||
| padding: 2rem; | ||
| text-align: center; | ||
| .app { | ||
| min-height: 100vh; | ||
| display: grid; | ||
| place-items: center; | ||
| padding: 1.5rem; | ||
| } | ||
|
|
||
| .panel { | ||
| width: 100%; | ||
| max-width: 760px; | ||
| border: 1px solid #2a2a2a; | ||
| border-radius: 16px; | ||
| background: #171717; | ||
| box-shadow: 0 12px 38px rgba(0, 0, 0, 0.32); | ||
| padding: 1.25rem; | ||
| } | ||
|
|
||
| .title { | ||
| margin: 0; | ||
| font-size: 1.8rem; | ||
| } | ||
|
|
||
| .subtitle { | ||
| color: #a0a0a0; | ||
| margin-top: 0.4rem; | ||
| } | ||
|
|
||
| .searchForm { | ||
| margin-top: 1rem; | ||
| display: flex; | ||
| gap: 0.6rem; | ||
| flex-wrap: wrap; | ||
| } | ||
|
Comment on lines
+28
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Standardize selector naming convention (camelCase vs kebab-case). Lines 28, 35, 47, and 103 use camelCase selectors while other selectors are lowercase single-word. This breaks naming consistency and makes stylesheet evolution harder. Consider migrating to kebab-case with a compatibility bridge. ♻️ Proposed migration-safe refactor-.searchForm {
+.searchForm,
+.search-form {
margin-top: 1rem;
display: flex;
gap: 0.6rem;
flex-wrap: wrap;
}
-.srOnly {
+.srOnly,
+.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
border: 0;
}
-.searchInput {
+.searchInput,
+.search-input {
flex: 1;
min-width: 220px;
padding: 0.7rem 0.8rem;
border-radius: 10px;
border: 1px solid `#3b3b3b`;
background: `#0f0f0f`;
color: `#f3f3f3`;
}
-.cardHeader {
+.cardHeader,
+.card-header {
display: flex;
gap: 0.85rem;
align-items: center;
}As per coding guidelines, "Ensure that ... [the code] adheres to similar naming conventions for classes, ids." Also applies to: 35-35, 47-47, 103-103 🤖 Prompt for AI Agents |
||
|
|
||
| .srOnly { | ||
| position: absolute; | ||
| width: 1px; | ||
| height: 1px; | ||
| padding: 0; | ||
| margin: -1px; | ||
| overflow: hidden; | ||
| clip-path: inset(50%); | ||
| white-space: nowrap; | ||
| border: 0; | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| .searchInput { | ||
| flex: 1; | ||
| min-width: 220px; | ||
| padding: 0.7rem 0.8rem; | ||
| border-radius: 10px; | ||
| border: 1px solid #3b3b3b; | ||
| background: #0f0f0f; | ||
| color: #f3f3f3; | ||
| } | ||
|
|
||
| .searchInput:focus { | ||
| outline: 2px solid #60a5fa; | ||
| outline-offset: 1px; | ||
| } | ||
|
|
||
| .button { | ||
| border: 0; | ||
| border-radius: 10px; | ||
| padding: 0.7rem 0.9rem; | ||
| font-weight: 600; | ||
| cursor: pointer; | ||
| text-decoration: none; | ||
| display: inline-flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| } | ||
|
|
||
| .button:disabled { | ||
| opacity: 0.65; | ||
| cursor: not-allowed; | ||
| } | ||
|
|
||
| .button.primary { | ||
| background: #2563eb; | ||
| color: #fff; | ||
| } | ||
|
|
||
| .button.ghost { | ||
| background: #0f0f0f; | ||
| color: #e8e8e8; | ||
| border: 1px solid #3b3b3b; | ||
| } | ||
|
|
||
| .error { | ||
| margin-top: 0.8rem; | ||
| color: #fca5a5; | ||
| } | ||
|
|
||
| .card { | ||
| margin-top: 1rem; | ||
| border: 1px solid #2f2f2f; | ||
| border-radius: 14px; | ||
| padding: 1rem; | ||
| background: #111111; | ||
| } | ||
|
|
||
| .cardHeader { | ||
| display: flex; | ||
| gap: 0.85rem; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .avatar { | ||
| width: 64px; | ||
| height: 64px; | ||
| border-radius: 12px; | ||
| } | ||
|
|
||
| .handle { | ||
| margin: 0.15rem 0 0; | ||
| color: #a0a0a0; | ||
| } | ||
|
|
||
| .description { | ||
| margin: 0.9rem 0; | ||
| color: #d6d6d6; | ||
| } | ||
|
|
||
| .stats { | ||
| margin: 0; | ||
| display: grid; | ||
| grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); | ||
| gap: 0.7rem; | ||
| } | ||
|
|
||
| .stats div { | ||
| padding: 0.55rem; | ||
| border: 1px solid #2d2d2d; | ||
| border-radius: 10px; | ||
| } | ||
|
|
||
| .stats dt { | ||
| color: #9f9f9f; | ||
| font-size: 0.82rem; | ||
| } | ||
|
|
||
| .stats dd { | ||
| margin: 0.2rem 0 0; | ||
| font-weight: 600; | ||
| } | ||
|
|
||
| .meta { | ||
| margin-top: 0.8rem; | ||
| color: #9f9f9f; | ||
| font-size: 0.88rem; | ||
| } | ||
|
|
||
| .actions { | ||
| margin-top: 0.9rem; | ||
| display: flex; | ||
| gap: 0.6rem; | ||
| flex-wrap: wrap; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,136 @@ | ||
| import './App.css' | ||
| import { useState, type FormEvent } from "react"; | ||
| import "./App.css"; | ||
| import { getOrganization, refreshOrganization } from "./cache/orgCache"; | ||
| import type { OrgResult } from "./api/github"; | ||
| import { uiText } from "./i18n/strings"; | ||
|
|
||
| function formatDate(iso: string): string { | ||
| try { | ||
| return new Intl.DateTimeFormat(undefined, { | ||
| year: "numeric", | ||
| month: "short", | ||
| day: "numeric", | ||
| }).format(new Date(iso)); | ||
| } catch { | ||
| return iso; | ||
| } | ||
| } | ||
|
|
||
| function App() { | ||
| const [query, setQuery] = useState(""); | ||
| const [result, setResult] = useState<OrgResult | null>(null); | ||
| const [loading, setLoading] = useState(false); | ||
| const [refreshing, setRefreshing] = useState(false); | ||
| const [error, setError] = useState<string | null>(null); | ||
|
|
||
| async function handleSearch(event: FormEvent<HTMLFormElement>) { | ||
| event.preventDefault(); | ||
| setError(null); | ||
| setLoading(true); | ||
|
|
||
| try { | ||
| const org = await getOrganization(query); | ||
| setResult(org); | ||
| } catch (err) { | ||
| setResult(null); | ||
| setError(err instanceof Error ? err.message : uiText.fetchErrorFallback); | ||
| } finally { | ||
| setLoading(false); | ||
| } | ||
| } | ||
|
|
||
| async function handleRefresh() { | ||
| if (!result) return; | ||
| setRefreshing(true); | ||
| setError(null); | ||
| try { | ||
| const refreshed = await refreshOrganization(result.org.login); | ||
| setResult(refreshed); | ||
| } catch (err) { | ||
| setError(err instanceof Error ? err.message : uiText.refreshErrorFallback); | ||
| } finally { | ||
| setRefreshing(false); | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <h1>Hello, OrgExplorer!</h1> | ||
| </> | ||
| ) | ||
| <main className="app"> | ||
| <section className="panel"> | ||
| <h1 className="title">{uiText.appTitle}</h1> | ||
| <p className="subtitle">{uiText.appSubtitle}</p> | ||
|
|
||
| <form className="searchForm" onSubmit={handleSearch}> | ||
| <label htmlFor="org-login" className="srOnly"> | ||
| {uiText.searchLabel} | ||
| </label> | ||
| <input | ||
| id="org-login" | ||
| className="searchInput" | ||
| placeholder={uiText.searchPlaceholder} | ||
| value={query} | ||
| onChange={(e) => setQuery(e.target.value)} | ||
| disabled={loading || refreshing} | ||
| /> | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <button className="button primary" type="submit" disabled={loading || refreshing}> | ||
| {loading ? uiText.searchLoading : uiText.searchIdle} | ||
| </button> | ||
| </form> | ||
|
|
||
| {error && <p className="error">{error}</p>} | ||
|
|
||
| {result && ( | ||
| <article className="card"> | ||
| <div className="cardHeader"> | ||
| <img className="avatar" src={result.org.avatar_url} alt="" /> | ||
| <div> | ||
| <h2>{result.org.name || result.org.login}</h2> | ||
| <p className="handle">@{result.org.login}</p> | ||
| </div> | ||
| </div> | ||
|
|
||
| {result.org.description && <p className="description">{result.org.description}</p>} | ||
|
|
||
| <dl className="stats"> | ||
| <div> | ||
| <dt>{uiText.publicRepos}</dt> | ||
| <dd>{result.org.public_repos.toLocaleString()}</dd> | ||
| </div> | ||
| <div> | ||
| <dt>{uiText.followers}</dt> | ||
| <dd>{result.org.followers.toLocaleString()}</dd> | ||
| </div> | ||
| <div> | ||
| <dt>{uiText.created}</dt> | ||
| <dd>{formatDate(result.org.created_at)}</dd> | ||
| </div> | ||
| <div> | ||
| <dt>{uiText.source}</dt> | ||
| <dd>{result.source === "cache" ? uiText.sourceCache : uiText.sourceApi}</dd> | ||
| </div> | ||
| </dl> | ||
|
|
||
| <p className="meta"> | ||
| {uiText.lastFetched}: {new Date(result.cachedAt).toLocaleTimeString()} | ||
| </p> | ||
|
|
||
| <div className="actions"> | ||
| <a className="button ghost" href={result.org.html_url} target="_blank" rel="noreferrer"> | ||
| {uiText.openGitHub} | ||
| </a> | ||
| <button | ||
| className="button primary" | ||
| type="button" | ||
| onClick={handleRefresh} | ||
| disabled={loading || refreshing} | ||
| > | ||
| {refreshing ? uiText.refreshLoading : uiText.refreshIdle} | ||
| </button> | ||
| </div> | ||
| </article> | ||
| )} | ||
| </section> | ||
| </main> | ||
| ); | ||
| } | ||
|
|
||
| export default App | ||
| export default App; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Use dynamic viewport unit fallback for mobile viewport stability.
At Line 2,
100vhcan cause visible jump/cropping on mobile browser UI show/hide. Add100dvhfallback for more stable layout behavior.📱 Proposed fix
.app { - min-height: 100vh; + min-height: 100vh; + min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; }As per coding guidelines, "Ensure that ... [the code] adheres to best practices recommended by lighthouse or similar tools for performance."
📝 Committable suggestion
🤖 Prompt for AI Agents