-
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
278aa67
commit b448f3c
Showing
44 changed files
with
1,098 additions
and
925 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, Icon, 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 { useActiveEnvironment } from "@src/features/environments/useActiveEnvironment"; | ||
|
||
export const ChangesItem: FC = () => { | ||
const { setSeenChangesToolTip } = useSliceMachineActions(); | ||
const open = useOpenChangesHoverCard(); | ||
const router = useRouter(); | ||
const { activeEnvironment } = useActiveEnvironment(); | ||
const isDevEnvironment = activeEnvironment?.kind === "dev"; | ||
|
||
const onClose = () => { | ||
setSeenChangesToolTip(); | ||
}; | ||
|
||
return ( | ||
<HoverCard | ||
open={open} | ||
openDelay={3000} | ||
onClose={onClose} | ||
side="right" | ||
sideOffset={24} | ||
collisionPadding={280} | ||
trigger={ | ||
<Button | ||
color="grey" | ||
disabled={isDevEnvironment} | ||
sx={{ marginBottom: 16 }} | ||
onClick={() => { | ||
void router.push("/changes"); | ||
}} | ||
> | ||
<Box alignItems="center" gap={4}> | ||
{isDevEnvironment ? ( | ||
<> | ||
<Icon name="refresh" size="medium" color="grey11" /> | ||
<Text>Auto-sync activated</Text> | ||
</> | ||
) : ( | ||
<> | ||
<Text>Review changes</Text> <ChangesCount /> | ||
</> | ||
)} | ||
</Box> | ||
</Button> | ||
} | ||
> | ||
<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.