Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add top bar back button to voting detail route #2873

Merged
merged 1 commit into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions packages/shared/routes/dashboard/TopNavigation.svelte
Original file line number Diff line number Diff line change
@@ -1,35 +1,50 @@
<script lang="typescript">
import { getContext } from 'svelte'
import { Readable } from 'svelte/store'
import { localize } from '@core/i18n'
import {
DashboardRoute,
dashboardRoute,
governanceRoute,
GovernanceRoute,
governanceRouter,
SettingsRoute,
settingsRoute,
settingsRouter,
} from '@core/router'
import { AccountSwitcher, Icon, Text } from 'shared/components'
import { WalletAccount } from 'shared/lib/typings/wallet'
import { DashboardRoute, dashboardRoute, SettingsRoute, settingsRoute, settingsRouter } from '@core/router'
import { getContext } from 'svelte'
import { Readable } from 'svelte/store'

export let onCreateAccount = (..._: any[]): void => {}
export let classes: string

const viewableAccounts = getContext<Readable<WalletAccount[]>>('viewableAccounts')
let showBackButton = false

$: showBackButton = isCorrectRoute($settingsRoute)
$: $dashboardRoute, $settingsRoute, $governanceRoute, checkToShowBackButton()

function isCorrectRoute(_: SettingsRoute): boolean {
return $settingsRoute !== SettingsRoute.Init
function checkToShowBackButton(): void {
showBackButton =
($dashboardRoute === DashboardRoute.Settings && $settingsRoute !== SettingsRoute.Init) ||
($dashboardRoute === DashboardRoute.Governance && $governanceRoute !== GovernanceRoute.Init)
}

function handleBackClick(): void {
switch ($dashboardRoute) {
case DashboardRoute.Settings:
$settingsRouter.previous()
break
case DashboardRoute.Governance:
$governanceRouter.previous()
break
default:
break
}
}
</script>

<div
class="bg-gray-200 dark:bg-gray-1000 border-solid border-b border-gray-300 dark:border-gray-1000 flex flex-row justify-center py-2 w-full {classes}"
class="bg-gray-200 dark:bg-gray-1000 border-solid border-b border-gray-300 dark:border-gray-1000 flex flex-row justify-center items-center py-2 w-full {classes}"
>
{#if showBackButton}
<button on:click={handleBackClick} class="absolute left-24 cursor-pointer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import { participationOverview } from 'shared/lib/participation/stores'
import { ParticipationEvent, ParticipationEventState, VotingEventAnswer } from 'shared/lib/participation/types'
import { closePopup, openPopup } from 'shared/lib/popup'
import { governanceRouter } from '@core/router'
import { GovernanceRoute } from '@core/router/enums'
import { handleTransactionEventData, selectedAccount, transferState } from 'shared/lib/wallet'
import { WalletAccount } from 'shared/lib/typings/wallet'
import { milestoneToDate, getBestTimeDuration, getDurationString } from 'shared/lib/time'
Expand Down Expand Up @@ -52,8 +50,6 @@
milestoneToDate(event?.information?.milestoneIndexEnd)?.getTime() -
milestoneToDate(event?.information?.milestoneIndexStart)?.getTime()

const handleBackClick = (): void => $governanceRouter.goTo(GovernanceRoute.Init)

const handleClick = (nextVote: VotingEventAnswer): void => {
const openGovernanceCastVotePopup = () =>
openPopup({
Expand Down Expand Up @@ -165,15 +161,6 @@
}
</script>

<div
on:click={handleBackClick}
class="inline-flex justify-between items-center w-20 p-2 pr-4 bg-white hover:bg-gray-100 border
rounded-lg border-solid border-gray-300 cursor-pointer mb-5"
>
<Icon icon="arrow-left" classes="w-4 h-4 text-gray-500" />
<Text type="p" smaller overrideColor classes="text-gray-800">{localize('actions.back')}</Text>
</div>

<div class="w-full h-full grid grid-cols-3 gap-4 min-h-0" style="grid-template-rows: min-content 1fr">
<DashboardPane classes="w-full h-full p-6 col-span-2 row-span-2 flex flex-col">
<div class="flex flex-start items-center mb-2">
Expand Down