-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auto-sync): Add an AutoSyncProvider and trigger a sync changes w…
…hen needed
- Loading branch information
1 parent
cc80883
commit 627ef87
Showing
48 changed files
with
1,228 additions
and
930 deletions.
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
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
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
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
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
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
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
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
117 changes: 117 additions & 0 deletions
117
packages/slice-machine/components/Navigation/ChangesItem.tsx
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,117 @@ | ||
import { type FC } from "react"; | ||
import { useRouter } from "next/router"; | ||
import { Box, Button, Text } from "@prismicio/editor-ui"; | ||
|
||
import { | ||
HoverCard, | ||
HoverCardCloseButton, | ||
HoverCardDescription, | ||
HoverCardMedia, | ||
HoverCardTitle, | ||
} from "@src/components/HoverCard"; | ||
import useSliceMachineActions from "@src/modules/useSliceMachineActions"; | ||
import { useNetwork } from "@src/hooks/useNetwork"; | ||
import { useAuthStatus } from "@src/hooks/useAuthStatus"; | ||
import { useUnSyncChanges } from "@src/features/sync/useUnSyncChanges"; | ||
import { AuthStatus } from "@src/modules/userContext/types"; | ||
import { useAutoSync } from "@src/features/sync/AutoSyncProvider"; | ||
import { AutoSyncStatusIndicator } from "@src/features/sync/components/AutoSyncStatusIndicator"; | ||
|
||
export const ChangesItem: FC = () => { | ||
const { setSeenChangesToolTip } = useSliceMachineActions(); | ||
const open = useOpenChangesHoverCard(); | ||
const router = useRouter(); | ||
const { autoSyncStatus } = useAutoSync(); | ||
|
||
const onClose = () => { | ||
setSeenChangesToolTip(); | ||
}; | ||
|
||
return ( | ||
<HoverCard | ||
open={open} | ||
openDelay={3000} | ||
onClose={onClose} | ||
side="right" | ||
sideOffset={24} | ||
collisionPadding={280} | ||
trigger={ | ||
<Box padding={{ bottom: 24 }}> | ||
{autoSyncStatus === "failed" || | ||
autoSyncStatus === "synced" || | ||
autoSyncStatus === "syncing" ? ( | ||
<AutoSyncStatusIndicator autoSyncStatus={autoSyncStatus} /> | ||
) : ( | ||
// TODO(DT-1942): This should be a Button with a link component for | ||
// accessibility | ||
<Button | ||
color="grey" | ||
onClick={() => { | ||
void router.push("/changes"); | ||
}} | ||
sx={{ width: "100%" }} | ||
> | ||
<Box alignItems="center" gap={4}> | ||
<Text>Review changes</Text> <ChangesCount /> | ||
</Box> | ||
</Button> | ||
)} | ||
</Box> | ||
} | ||
> | ||
<HoverCardTitle>Push your changes</HoverCardTitle> | ||
<HoverCardMedia component="image" src="/push.png" /> | ||
<HoverCardDescription> | ||
When you click Save, your changes are saved locally. Then, you can push | ||
your models to Prismic from the Changes page. | ||
</HoverCardDescription> | ||
<HoverCardCloseButton>Got it</HoverCardCloseButton> | ||
</HoverCard> | ||
); | ||
}; | ||
|
||
export const ChangesCount: FC = () => { | ||
const isOnline = useNetwork(); | ||
const authStatus = useAuthStatus(); | ||
const { unSyncedSlices, unSyncedCustomTypes } = useUnSyncChanges(); | ||
const numberOfChanges = unSyncedSlices.length + unSyncedCustomTypes.length; | ||
|
||
if ( | ||
!isOnline || | ||
authStatus === AuthStatus.UNAUTHORIZED || | ||
authStatus === AuthStatus.FORBIDDEN | ||
) { | ||
return null; | ||
} | ||
|
||
if (numberOfChanges === 0) { | ||
return null; | ||
} | ||
|
||
const formattedNumberOfChanges = numberOfChanges > 9 ? "+9" : numberOfChanges; | ||
|
||
return ( | ||
<Box padding={{ inline: 6 }} borderRadius={10} backgroundColor="grey5"> | ||
<Text color="grey11" variant="small"> | ||
{formattedNumberOfChanges} | ||
</Text> | ||
</Box> | ||
); | ||
}; | ||
|
||
// TODO(DT-1925): Reactivate this feature | ||
const useOpenChangesHoverCard = () => { | ||
// const { hasSeenChangesToolTip, hasSeenSimulatorToolTip } = useSelector( | ||
// (store: SliceMachineStoreType) => ({ | ||
// hasSeenChangesToolTip: userHasSeenChangesToolTip(store), | ||
// hasSeenSimulatorToolTip: userHasSeenSimulatorToolTip(store), | ||
// }), | ||
// ); | ||
|
||
// return ( | ||
// !hasSeenChangesToolTip && | ||
// hasSeenSimulatorToolTip | ||
// ); | ||
|
||
return false; | ||
}; |
Oops, something went wrong.