fix: update shortcut

This commit is contained in:
Steven
2023-12-23 23:52:44 +08:00
parent b73f7070e4
commit 546d87ca0b
28 changed files with 1607 additions and 1345 deletions

View File

@ -28,11 +28,11 @@ interface State {
const ShortcutDetail = () => {
const { t } = useTranslation();
const params = useParams();
const shortcutName = params["*"] || "";
const shortcutId = Number(params["shortcutId"]);
const navigateTo = useNavigateTo();
const shortcutStore = useShortcutStore();
const userStore = useUserStore();
const shortcut = shortcutStore.getShortcutByName(shortcutName);
const shortcut = shortcutStore.getShortcutById(shortcutId);
const currentUser = useUserStore().getCurrentUser();
const [state, setState] = useState<State>({
showEditDrawer: false,
@ -46,11 +46,11 @@ const ShortcutDetail = () => {
useEffect(() => {
(async () => {
const shortcut = await shortcutStore.getOrFetchShortcutByName(shortcutName);
const shortcut = await shortcutStore.getOrFetchShortcutById(shortcutId);
await userStore.getOrFetchUserById(shortcut.creatorId);
loadingState.setFinish();
})();
}, [shortcutName]);
}, [shortcutId]);
if (loadingState.isLoading) {
return null;
@ -67,7 +67,7 @@ const ShortcutDetail = () => {
content: `Are you sure to delete shortcut \`${shortcut.name}\`? You cannot undo this action.`,
style: "danger",
onConfirm: async () => {
await shortcutStore.deleteShortcut(shortcut.name);
await shortcutStore.deleteShortcut(shortcut.id);
navigateTo("/", {
replace: true,
});
@ -198,7 +198,7 @@ const ShortcutDetail = () => {
<Icon.BarChart2 className="w-6 h-auto mr-1" />
{t("analytics.self")}
</h3>
<AnalyticsView className="mt-4 w-full grid grid-cols-1 sm:grid-cols-2 gap-2 sm:gap-4" shortcutName={shortcut.name} />
<AnalyticsView className="mt-4 w-full grid grid-cols-1 sm:grid-cols-2 gap-2 sm:gap-4" shortcutId={shortcut.id} />
</div>
</div>
@ -206,7 +206,7 @@ const ShortcutDetail = () => {
{state.showEditDrawer && (
<CreateShortcutDrawer
shortcutName={shortcut.name}
shortcutId={shortcut.id}
onClose={() =>
setState({
...state,