-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #730 from MuckRock/allanlasser/issue598
Guided tours for first-time users
- Loading branch information
Showing
13 changed files
with
288 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,39 @@ | ||
<script lang="ts"> | ||
import { _ } from "svelte-i18n"; | ||
import Dropdown from "@/common/Dropdown2.svelte"; | ||
import Menu from "@/common/Menu.svelte"; | ||
import { page } from "$app/stores"; | ||
import { _ } from "svelte-i18n"; | ||
import { | ||
ChevronDown12, | ||
ChevronUp12, | ||
Code16, | ||
CommentDiscussion16, | ||
Gift16, | ||
Mail16, | ||
Milestone16, | ||
Plug16, | ||
Question24, | ||
Search16, | ||
} from "svelte-octicons"; | ||
import Dropdown, { closeDropdown } from "@/common/Dropdown2.svelte"; | ||
import Menu from "@/common/Menu.svelte"; | ||
import SidebarItem from "../sidebar/SidebarItem.svelte"; | ||
import Premium from "@/common/icons/Premium.svelte"; | ||
import { startTour, isTourAvailable } from "../onboarding/GuidedTour.svelte"; | ||
export let position = "bottom right"; | ||
function close() { | ||
closeDropdown("help"); | ||
} | ||
function onTourClick() { | ||
close(); | ||
startTour(); | ||
} | ||
$: showTour = isTourAvailable($page?.route?.id); | ||
</script> | ||
|
||
<!-- Help Menu --> | ||
|
@@ -33,31 +49,41 @@ | |
</div> | ||
</SidebarItem> | ||
<Menu> | ||
<SidebarItem href="/help/faq/"> | ||
{#if showTour} | ||
<SidebarItem hover on:click={onTourClick}> | ||
<Milestone16 slot="start" /> | ||
Guided Tour | ||
</SidebarItem> | ||
{/if} | ||
<SidebarItem href="/help/faq/" on:click={close}> | ||
<CommentDiscussion16 slot="start" /> | ||
{$_("authSection.help.faq")} | ||
</SidebarItem> | ||
<SidebarItem href="/help/search/"> | ||
<SidebarItem href="/help/search/" on:click={close}> | ||
<Search16 slot="start" /> | ||
{$_("authSection.help.searchDocs")} | ||
</SidebarItem> | ||
<SidebarItem href="/help/api/"> | ||
<SidebarItem href="/help/api/" on:click={close}> | ||
<Code16 slot="start" /> | ||
{$_("authSection.help.apiDocs")} | ||
</SidebarItem> | ||
<SidebarItem href="/help/add-ons/"> | ||
<SidebarItem href="/help/add-ons/" on:click={close}> | ||
<Plug16 slot="start" /> | ||
{$_("authSection.help.addOns")} | ||
</SidebarItem> | ||
<SidebarItem href="/help/premium/"> | ||
<SidebarItem href="/help/premium/" on:click={close}> | ||
<Premium slot="start" /> | ||
{$_("authSection.help.premium")} | ||
</SidebarItem> | ||
<SidebarItem href="https://www.muckrock.com/donate/"> | ||
<SidebarItem href="https://www.muckrock.com/donate/" on:click={close}> | ||
<Gift16 slot="start" /> | ||
{$_("authSection.help.donate")} | ||
</SidebarItem> | ||
<SidebarItem href="mailto:[email protected]" target="_blank"> | ||
<SidebarItem | ||
href="mailto:[email protected]" | ||
target="_blank" | ||
on:click={close} | ||
> | ||
<Mail16 slot="start" /> | ||
{$_("authSection.help.emailUs")} | ||
</SidebarItem> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<!-- @component | ||
The GuidedTour will run on different routes, introducing that page's | ||
UI to new users. We keep track of which tours the user has already | ||
taken in a LocalStorage object. If a script exists for the current route, | ||
and if the user hasn't already taken it, we'll prompt them to take the guided tour. | ||
--> | ||
<script lang="ts" context="module"> | ||
import type { Maybe } from "$lib/api/types"; | ||
import "driver.js/dist/driver.css"; | ||
import { page } from "$app/stores"; | ||
import { driver, type Driver, type DriveStep, type Config } from "driver.js"; | ||
import { get } from "svelte/store"; | ||
import { StorageManager } from "$lib/utils/storage"; | ||
import { scripts } from "./scripts"; | ||
const storage = new StorageManager("guided-tour"); | ||
let driverObj: Driver; | ||
const driverConfig: Config = { | ||
showProgress: true, | ||
popoverClass: "dc-driver", | ||
overlayColor: "rgba(92, 113, 124, 0.5)", | ||
}; | ||
type Tours = Record<string, boolean>; | ||
export function getRoute(): Maybe<string> { | ||
return get(page)?.route?.id; | ||
} | ||
export function getScript(route?: string): Maybe<DriveStep[]> { | ||
const currentRoute = route ?? getRoute(); | ||
return scripts[currentRoute]; | ||
} | ||
export function getTourHistory(): Tours { | ||
return storage.get<Tours, {}>("tours", {}); | ||
} | ||
export function startTour(): void { | ||
driverObj?.drive(); | ||
} | ||
export function endTour(): void { | ||
const route = getRoute(); | ||
const history = getTourHistory(); | ||
storage.set("tours", { ...history, [route]: false }); | ||
driverObj.destroy(); | ||
} | ||
export function isTourAvailable(route?: string): boolean { | ||
return Boolean(getScript(route)); | ||
} | ||
</script> | ||
|
||
<script lang="ts"> | ||
import { onMount } from "svelte"; | ||
onMount(() => { | ||
// do we have a tour? | ||
const steps = getScript(); | ||
if (steps) { | ||
driverObj = driver({ | ||
...driverConfig, | ||
steps, | ||
onDestroyStarted: endTour, | ||
}); | ||
// should we start the tour? | ||
const currentRoute = getRoute(); | ||
const history = getTourHistory(); | ||
const offerTour = history[currentRoute] ?? true; | ||
if (offerTour) { | ||
startTour(); | ||
} | ||
} | ||
}); | ||
</script> | ||
|
||
<slot /> | ||
|
||
<style> | ||
:global( | ||
.driver-popover, | ||
.driver-popover-title, | ||
.driver-popover-description, | ||
.driver-popover-progress-text, | ||
.driver-popover-footer button | ||
) { | ||
font-family: var(--font-sans); | ||
} | ||
:global(.driver-popover-title) { | ||
font-weight: var(--font-semibold); | ||
line-height: 1.2; | ||
font-size: var(--font-lg); | ||
color: var(--gray-5); | ||
} | ||
:global(.driver-popover-description) { | ||
font-size: var(--font-sm); | ||
line-height: 1.4; | ||
color: var(--gray-5); | ||
} | ||
:global(.driver-popover-progress-text) { | ||
color: var(--gray-4); | ||
} | ||
:global(.driver-popover-footer button) { | ||
font-weight: var(--font-semibold); | ||
} | ||
:global(button.driver-popover-next-btn) { | ||
border-color: var(--blue-4); | ||
background-color: var(--blue-3); | ||
color: var(--white); | ||
text-shadow: none; | ||
} | ||
:global(button.driver-popover-next-btn:hover) { | ||
background-color: var(--blue-4); | ||
color: var(--white); | ||
text-shadow: none; | ||
} | ||
</style> |
Oops, something went wrong.