edit-access+redirect

This commit is contained in:
Untone 2024-03-05 16:01:47 +03:00
parent 9b7079def5
commit f8bf3d86a0
3 changed files with 21 additions and 3 deletions

View File

@ -51,7 +51,10 @@ const DialogAvatar = (props: Props) => {
<Show when={Boolean(props.url)} fallback={<div class={styles.letter}>{nameFirstLetter()}</div>}> <Show when={Boolean(props.url)} fallback={<div class={styles.letter}>{nameFirstLetter()}</div>}>
<div <div
class={styles.imageHolder} class={styles.imageHolder}
style={{ 'background-image': `url(${getImageUrl(props.url, { width: 40, height: 40 })})` }} style={{ 'background-image': `url(
${props.url.includes('discours.io') ? getImageUrl(props.url, { width: 40, height: 40 }) : props.url }
)`
}}
/> />
</Show> </Show>
</div> </div>

View File

@ -210,6 +210,13 @@ export const apiClient = {
return resp.data.get_shout return resp.data.get_shout
}, },
getMyShout: async (shout_id: number) => {
const resp = await apiClient.private.query(shoutLoad, { shout_id }).toPromise()
if (resp.error) console.error(resp)
return resp.data.get_shout
},
getShouts: async (options: LoadShoutsOptions) => { getShouts: async (options: LoadShoutsOptions) => {
const resp = await publicGraphQLClient.query(shoutsLoadBy, { options }).toPromise() const resp = await publicGraphQLClient.query(shoutsLoadBy, { options }).toPromise()
if (resp.error) console.error(resp) if (resp.error) console.error(resp)

View File

@ -7,8 +7,10 @@ import { useLocalize } from '../context/localize'
import { apiClient } from '../graphql/client/core' import { apiClient } from '../graphql/client/core'
import { Shout } from '../graphql/schema/core.gen' import { Shout } from '../graphql/schema/core.gen'
import { useRouter } from '../stores/router' import { useRouter } from '../stores/router'
import { router } from '../stores/router'
import { LayoutType } from './types' import { LayoutType } from './types'
import { redirectPage } from "@nanostores/router";
const EditView = lazy(() => import('../components/Views/EditView/EditView')) const EditView = lazy(() => import('../components/Views/EditView/EditView'))
@ -21,8 +23,14 @@ export const EditPage = () => {
const [shout, setShout] = createSignal<Shout>(null) const [shout, setShout] = createSignal<Shout>(null)
onMount(async () => { onMount(async () => {
const loadedShout = await apiClient.getShoutById(shoutId()) const loadedShout = await apiClient.getMyShout(shoutId())
setShout(loadedShout) console.log(loadedShout)
if (loadedShout) {
setShout(loadedShout)
}
else {
redirectPage(router, 'drafts')
}
}) })
const title = createMemo(() => { const title = createMemo(() => {