-
Notifications
You must be signed in to change notification settings - Fork 47
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
Open
madebyisaacr
wants to merge
16
commits into
main
Choose a base branch
from
notion-progress-bar
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 all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
773a066
Improve no access state
madebyisaacr fb16441
Add progress bar modal
madebyisaacr 6832b3c
Report item count when loaded, remove cancel button
madebyisaacr 9acd01c
Load item count progress, format numbers
madebyisaacr f390fc2
Eslint fix
madebyisaacr 99048a4
Use tertiary color
madebyisaacr 780c629
Make percent style primary
madebyisaacr c52e019
Show progress bar when syncing
madebyisaacr c40e1d9
Clean up progress app code
madebyisaacr d1fbf13
Fix ts errors
madebyisaacr 6206033
Move to react component
madebyisaacr 501e63b
Include initial loading in percent
madebyisaacr 47b2bab
Content field enabled
madebyisaacr 29f4ea6
Animate progress bar
madebyisaacr 6e1e3be
Motion package
madebyisaacr 1c172ff
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.