From dc44e9f999b5982a4d7bdee59ea44122b40372d1 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Thu, 16 Mar 2023 07:52:24 -0700 Subject: [PATCH] Allow unauth users to edit their remixed parties --- components/Header/index.tsx | 8 ++++++++ components/Party/index.tsx | 7 +------ utils/userToken.tsx | 4 ++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/components/Header/index.tsx b/components/Header/index.tsx index a2d86abb..011362a4 100644 --- a/components/Header/index.tsx +++ b/components/Header/index.tsx @@ -12,6 +12,7 @@ import { accountState, initialAccountState } from '~utils/accountState' import { appState, initialAppState } from '~utils/appState' import { getLocalId } from '~utils/localId' import { retrieveLocaleCookies } from '~utils/retrieveCookies' +import { setEditKey, storeEditKey } from '~utils/userToken' import { DropdownMenu, @@ -196,6 +197,13 @@ const Header = () => { .remix({ shortcode: partySnapshot.shortcode, body: body }) .then((response) => { const remix = response.data.party + + // Store the edit key in local storage + if (remix.edit_key) { + storeEditKey(remix.id, remix.edit_key) + setEditKey(remix.id, remix.user) + } + router.push(`/p/${remix.shortcode}`) setRemixToastOpen(true) }) diff --git a/components/Party/index.tsx b/components/Party/index.tsx index 3bc61ce1..900898fb 100644 --- a/components/Party/index.tsx +++ b/components/Party/index.tsx @@ -3,7 +3,6 @@ import { getCookie } from 'cookies-next' import { useRouter } from 'next/router' import { subscribe, useSnapshot } from 'valtio' import clonedeep from 'lodash.clonedeep' -import ls from 'local-storage' import PartySegmentedControl from '~components/PartySegmentedControl' import PartyDetails from '~components/PartyDetails' @@ -17,7 +16,7 @@ import { appState, initialAppState } from '~utils/appState' import { getLocalId } from '~utils/localId' import { GridType } from '~utils/enums' import { retrieveCookies } from '~utils/retrieveCookies' -import { setEditKey, unsetEditKey } from '~utils/userToken' +import { setEditKey, storeEditKey, unsetEditKey } from '~utils/userToken' import type { DetailsObject } from '~types' @@ -240,10 +239,6 @@ const Party = (props: Props) => { return team } - const storeEditKey = (id: string, key: string) => { - ls(id, key) - } - const storeCharacters = (list: Array) => { list.forEach((object: GridCharacter) => { if (object.position != null) diff --git a/utils/userToken.tsx b/utils/userToken.tsx index 08563bda..aebd920e 100644 --- a/utils/userToken.tsx +++ b/utils/userToken.tsx @@ -26,6 +26,10 @@ export const setHeaders = ( } } +export const storeEditKey = (id: string, key: string) => { + ls(id, key) +} + export const setEditKey = (id: string, user?: User) => { if (!user) { const edit_key = get(id)