-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat: Add loading component to recent search #94
Open
amiabl-programr
wants to merge
15
commits into
jargonsdev:main
Choose a base branch
from
amiabl-programr:add-loading-component-to-recent-search
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
28cc8ed
Merge pull request #1 from jargonsdev/main
amiabl-programr cc56d75
Merge pull request #2 from jargonsdev/main
amiabl-programr f92b8c0
Merge pull request #3 from jargonsdev/main
amiabl-programr 16c0dd7
feat: add loading component to recent searches island
amiabl-programr a17fa90
chore: Add a cleanup function using clearTimeout
amiabl-programr 41fb8fe
Merge pull request #4 from jargonsdev/main
amiabl-programr ebf7b03
Merge pull request #5 from jargonsdev/main
amiabl-programr 6f7380c
Merge branch 'main' of https://github.com/amiabl-programr/jargons.dev…
amiabl-programr 8e4e3e2
feat: add loading component to recent searches island
amiabl-programr 1c31f7a
chore: Add a cleanup function using clearTimeout
amiabl-programr 468ac5d
Merge branch 'add-loading-component-to-recent-search' of https://gith…
amiabl-programr d605317
rename component
amiabl-programr 405e8e4
import recent searches file
amiabl-programr 1a0b50f
add loading component to recent search
amiabl-programr d53e15f
Merge branch 'main' into add-loading-component-to-recent-search
amiabl-programr 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 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 @@ | ||
|
||
|
||
export default function RecentSearchesLoading ({ recentSearches }) { | ||
return ( | ||
<div className="space-y-3 ml-2 mt-4 md:mt-6"> | ||
<h2 className="text-2xl md:text-4xl font-black">Recent</h2> | ||
<ol className="space-y-1.5 underline"> | ||
{Object.values(recentSearches).slice(0, 5).map((item, i) => ( | ||
<li key={i}> | ||
<div | ||
className="placeholder-text bg-gray-300 rounded animate-pulse" | ||
style={{ width: `${item.word.length * 8}px`, height: '24px' }} | ||
></div> | ||
</li> | ||
))} | ||
</ol> | ||
</div> | ||
); | ||
}; | ||
|
This file contains 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 |
---|---|---|
@@ -1,32 +1,40 @@ | ||
import { useEffect } from "react"; | ||
import { useStore } from "@nanostores/react"; | ||
import { useEffect, useState } from 'react'; | ||
import { useStore } from '@nanostores/react'; | ||
import { $recentSearches } from "../../lib/stores/search.js"; | ||
import RecentSearchesLoading from './recent-searches-loading'; | ||
|
||
/** | ||
* Recent Searches Component - An Island that displays a user's last 5 searches | ||
* | ||
* @todo implement a default list instead of `null` when no `$recentSearch` is found | ||
* @todo implement loading component to avoid flickering UI | ||
*/ | ||
export default function RecentSearches() { | ||
const recentSearches = useStore($recentSearches); | ||
const [isLoading, setIsLoading] = useState(true); | ||
|
||
useEffect(() => { | ||
$recentSearches.set({...JSON.parse(localStorage.getItem("jargons.dev:recent_searches"))}) | ||
const savedSearches = JSON.parse(localStorage.getItem("jargons.dev:recent_searches")); | ||
if (savedSearches) { | ||
$recentSearches.set(savedSearches); | ||
} | ||
const timer = setTimeout(() => { | ||
setIsLoading(false); | ||
}, 2000); | ||
|
||
return () => clearTimeout(timer); | ||
}, []); | ||
|
||
if (isLoading) { | ||
return <RecentSearchesLoading recentSearches={recentSearches} />; | ||
} | ||
|
||
return Object.values(recentSearches).length ? ( | ||
<div className="space-y-3 ml-2 mt-4 md:mt-6"> | ||
<h2 className="text-2xl md:text-4xl font-black">Recent</h2> | ||
<ol className="space-y-1.5 underline"> | ||
<h2 className="text-2xl md:text-4xl font-black">Recent</h2> | ||
<ol className="space-y-1.5 underline"> | ||
{Object.values(recentSearches).slice(0, 5).map((item, i) => ( | ||
<li key={i}> | ||
<a href={item.url}> | ||
{ item.word } | ||
{item.word} | ||
</a> | ||
</li> | ||
))} | ||
</ol> | ||
</div> | ||
</ol> | ||
</div> | ||
) : null; | ||
} | ||
} |
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.
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.
The
recentSearches
will befalse
on the server, so theLoadingComponent
in place ofnull
would be loaded from the server until hydrated on the client to either load the recent searches in local storage or notThere 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.
Okay... But if the local storage is empty, the loading component will remain on the page
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.
Oh my! that is true 🤔
So, we could use an Effect to understand when the page is loaded then kick the
LoadingComponent
orRecentSearchComponent
ornull
on that, something like....Thinking out loud here 😉