-
Notifications
You must be signed in to change notification settings - Fork 49
Notion: add progress bar #507
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
16 commits
Select commit
Hold shift + click to select a range
0d2d685
Improve no access state
madebyisaacr 9c742da
Add progress bar modal
madebyisaacr c650d85
Report item count when loaded, remove cancel button
madebyisaacr 94c91a9
Load item count progress, format numbers
madebyisaacr e0541ee
Eslint fix
madebyisaacr bca1053
Use tertiary color
madebyisaacr 5c9bacf
Make percent style primary
madebyisaacr 4e29564
Show progress bar when syncing
madebyisaacr dc0637c
Clean up progress app code
madebyisaacr 136fa11
Fix ts errors
madebyisaacr f79a797
Move to react component
madebyisaacr cc16afc
Include initial loading in percent
madebyisaacr 4531522
Content field enabled
madebyisaacr 2ca2dc0
Animate progress bar
madebyisaacr 372a175
Motion package
madebyisaacr 6d22a34
Update Progress.tsx
madebyisaacr 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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,75 @@ | ||
| import { framer } from "framer-plugin" | ||
| import { animate, motion, useMotionValue, useTransform } from "motion/react" | ||
| import { useEffect } from "react" | ||
|
|
||
| const LOADING_PHASE_MAX = 20 | ||
| const LOADING_PHASE_K = 150 | ||
|
|
||
| export function Progress({ | ||
| current, | ||
| total, | ||
| contentFieldEnabled = true, | ||
| }: { | ||
| current: number | ||
| total: number | ||
| /** When false, loading phase spans 0–100% (no per-page content fetch). */ | ||
| contentFieldEnabled?: boolean | ||
| }) { | ||
| const percent = getProgressPercent(current, total, contentFieldEnabled) | ||
| const formatter = new Intl.NumberFormat("en-US") | ||
| const formattedCurrent = formatter.format(current) | ||
| const formattedTotal = formatter.format(total) | ||
|
|
||
| const animatedValue = useMotionValue(0) | ||
|
|
||
| useEffect(() => { | ||
| // Clear menu while syncing | ||
| void framer.setMenu([]) | ||
| }, []) | ||
|
|
||
| useEffect(() => { | ||
| void animate(animatedValue, percent, { type: "tween" }) | ||
| }, [percent, animatedValue]) | ||
|
|
||
| return ( | ||
| <main> | ||
| <div className="progress-bar-text"> | ||
| <span className="progress-bar-percent">{percent.toFixed(1).replace(".0", "")}%</span> | ||
| <span> | ||
| {formattedCurrent} / {formattedTotal} | ||
| </span> | ||
| </div> | ||
| <div className="progress-bar"> | ||
| <motion.div | ||
| className="progress-bar-fill" | ||
| style={{ | ||
| width: useTransform(() => `${animatedValue.get()}%`), | ||
| }} | ||
| /> | ||
| </div> | ||
| <p> | ||
| {current > 0 ? "Syncing" : "Loading data"}… please keep the plugin open until the process is complete. | ||
| </p> | ||
| </main> | ||
| ) | ||
| } | ||
|
|
||
| function getProgressPercent(current: number, total: number, contentFieldEnabled: boolean): number { | ||
| if (total > 0 && contentFieldEnabled) { | ||
| if (current > 0) { | ||
| // Processing phase: base 20%, remaining 80% from current/total | ||
| return LOADING_PHASE_MAX + 80 * (current / total) | ||
| } | ||
| // Loading phase: 0–20% with total/(total+k) so we approach but never reach 20% | ||
| return LOADING_PHASE_MAX * (total / (total + LOADING_PHASE_K)) | ||
| } | ||
| if (total > 0 && !contentFieldEnabled) { | ||
| if (current > 0) { | ||
| // No per-page fetch: loading is done, show 100% | ||
| return 100 | ||
| } | ||
| // Loading phase: 0–100% with total/(total+k) | ||
| return 100 * (total / (total + LOADING_PHASE_K)) | ||
| } | ||
| return 0 | ||
| } |
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.