feat: discard changes (#484)
This commit is contained in:
@@ -60,6 +60,7 @@
|
||||
"Preview": "プレビュー",
|
||||
"Publish": "公開",
|
||||
"Update": "更新",
|
||||
"Discard Changes": "変更を破棄",
|
||||
"Publish at": "公開日時",
|
||||
"This post will be accessible from this time": "この記事は、この時間からアクセス可能になります",
|
||||
"This page will be accessible from this time": "このページは、この時間からアクセス可能になります",
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
"Preview": "預覽",
|
||||
"Publish": "發布",
|
||||
"Update": "更新",
|
||||
"Discard Changes": "捨棄變更",
|
||||
"Publish at": "發布時間",
|
||||
"This post will be accessible from this time": "此文章將從此時間開始可瀏覽",
|
||||
"This page will be accessible from this time": "此頁面將從此時間開始可瀏覽",
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
"Preview": "预览",
|
||||
"Publish": "发布",
|
||||
"Update": "更新",
|
||||
"Discard Changes": "放弃变更",
|
||||
"Publish at": "发布时间",
|
||||
"This post will be accessible from this time": "此文章将从此时间开始可访问",
|
||||
"This page will be accessible from this time": "此页面将从此时间开始可访问",
|
||||
|
||||
@@ -17,6 +17,8 @@ export const OptionsButton: React.FC<{
|
||||
isRendering: boolean
|
||||
published: boolean
|
||||
isPost: boolean
|
||||
isModified: boolean
|
||||
discardChanges: () => void
|
||||
}> = ({
|
||||
visibility,
|
||||
previewPage,
|
||||
@@ -26,6 +28,8 @@ export const OptionsButton: React.FC<{
|
||||
published,
|
||||
propertiesWidget,
|
||||
isPost,
|
||||
isModified,
|
||||
discardChanges,
|
||||
}) => {
|
||||
const { t } = useTranslation("dashboard")
|
||||
|
||||
@@ -111,6 +115,20 @@ export const OptionsButton: React.FC<{
|
||||
</button>
|
||||
)}
|
||||
</Menu.Item>
|
||||
{isModified && (
|
||||
<Menu.Item>
|
||||
{({ active }) => (
|
||||
<button
|
||||
className={`${
|
||||
active ? "bg-accent text-white" : "text-gray-900"
|
||||
} group flex w-full items-center rounded-md px-2 py-2 text-sm`}
|
||||
onClick={discardChanges}
|
||||
>
|
||||
{t("Discard Changes")}
|
||||
</button>
|
||||
)}
|
||||
</Menu.Item>
|
||||
)}
|
||||
{published && (
|
||||
<Menu.Item>
|
||||
{({ active }) => (
|
||||
|
||||
@@ -12,7 +12,18 @@ export const PublishButton: React.FC<{
|
||||
isDisabled: boolean
|
||||
twitterShareUrl?: string
|
||||
isPost: boolean
|
||||
}> = ({ save, published, isSaving, isDisabled, twitterShareUrl, isPost }) => {
|
||||
isModified: boolean
|
||||
discardChanges: () => void
|
||||
}> = ({
|
||||
save,
|
||||
discardChanges,
|
||||
published,
|
||||
isSaving,
|
||||
isDisabled,
|
||||
isModified,
|
||||
twitterShareUrl,
|
||||
isPost,
|
||||
}) => {
|
||||
const [showDropdown, setShowDropdown] = useState(false)
|
||||
const dropdownRef = useRef<HTMLDivElement | null>(null)
|
||||
const triggerRef = useRef<HTMLButtonElement | null>(null)
|
||||
@@ -70,6 +81,15 @@ export const PublishButton: React.FC<{
|
||||
<i className="icon-[mingcute--twitter-line] mr-1"></i>
|
||||
{t("Share to Twitter")}
|
||||
</button>
|
||||
{isModified && (
|
||||
<button
|
||||
className="flex w-full h-8 hover:bg-zinc-100 items-center px-5"
|
||||
onClick={discardChanges}
|
||||
>
|
||||
<i className="icon-[mingcute--delete-back-line] mr-1"></i>
|
||||
{t("Discard Changes")}
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
className="flex w-full h-8 hover:bg-zinc-100 items-center px-5"
|
||||
onClick={() => setDeleteConfirmModalOpen(true)}
|
||||
|
||||
@@ -523,6 +523,19 @@ export default function SubdomainEditor() {
|
||||
/>
|
||||
)
|
||||
|
||||
const discardChanges = useCallback(() => {
|
||||
if (draftKey) {
|
||||
delStorage(draftKey)
|
||||
queryClient.invalidateQueries(["getPagesBySite", site.data?.characterId])
|
||||
queryClient.invalidateQueries([
|
||||
"getPage",
|
||||
draftKey.replace(`draft-${site.data?.characterId}-`, ""),
|
||||
])
|
||||
} else {
|
||||
queryClient.invalidateQueries(["getPage", pageId])
|
||||
}
|
||||
}, [draftKey])
|
||||
|
||||
return (
|
||||
<>
|
||||
<DashboardMain fullWidth>
|
||||
@@ -555,6 +568,8 @@ export default function SubdomainEditor() {
|
||||
propertiesWidget={extraProperties}
|
||||
previewPage={onPreviewButtonClick}
|
||||
isPost={isPost}
|
||||
isModified={visibility === PageVisibilityEnum.Modified}
|
||||
discardChanges={discardChanges}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
@@ -592,6 +607,8 @@ export default function SubdomainEditor() {
|
||||
visibility !== PageVisibilityEnum.Draft
|
||||
}
|
||||
isPost={isPost}
|
||||
isModified={visibility === PageVisibilityEnum.Modified}
|
||||
discardChanges={discardChanges}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user