mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 14:20:42 +08:00
Add dismissible hints
Co-authored-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
co-authored by
Rūdolfs Ošiņš
parent
a03c413343
commit
20f5aa1f1e
@@ -13,6 +13,8 @@
|
||||
import * as utils from "@app/lib/utils";
|
||||
|
||||
import Button from "@app/components/Button.svelte";
|
||||
import { hints } from "@app/lib/hints";
|
||||
|
||||
import Icon from "@app/components/Icon.svelte";
|
||||
import Markdown from "@app/components/Markdown.svelte";
|
||||
import Textarea from "@app/components/Textarea.svelte";
|
||||
@@ -290,6 +292,38 @@
|
||||
margin-left: 0.25rem;
|
||||
}
|
||||
|
||||
.textarea-wrap {
|
||||
position: relative;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
flex: 1;
|
||||
}
|
||||
.markdown-hint {
|
||||
position: absolute;
|
||||
bottom: 0.375rem;
|
||||
right: 0.5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
color: var(--color-text-quaternary);
|
||||
opacity: 0.6;
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
.markdown-hint-dismiss {
|
||||
background: none;
|
||||
border: 1px solid var(--color-border-subtle);
|
||||
border-radius: var(--border-radius-sm);
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
font: var(--txt-body-s-regular);
|
||||
padding: 0 0.375rem;
|
||||
line-height: 1.25rem;
|
||||
}
|
||||
.markdown-hint-dismiss:hover {
|
||||
background-color: var(--color-surface-subtle);
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
.preview {
|
||||
width: 100%;
|
||||
font: var(--txt-body-m-regular);
|
||||
@@ -308,30 +342,48 @@
|
||||
</style>
|
||||
|
||||
<div class="comment-section" aria-label="extended-textarea" class:inline>
|
||||
{#if preview}
|
||||
<div class="preview" style:min-height={styleMinHeight}>
|
||||
{#if body.trim().length === 0}
|
||||
<span class="txt-missing">Nothing to preview.</span>
|
||||
{:else}
|
||||
<Markdown {rid} breaks content={body} />
|
||||
<div class="textarea-wrap">
|
||||
{#if preview}
|
||||
<div class="preview" style:min-height={styleMinHeight}>
|
||||
{#if body.trim().length === 0}
|
||||
<span class="txt-missing">Nothing to preview.</span>
|
||||
{:else}
|
||||
<Markdown {rid} breaks content={body} />
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<Textarea
|
||||
size={textAreaSize}
|
||||
styleAlignItems="flex-start"
|
||||
{draggingOver}
|
||||
{borderVariant}
|
||||
{stylePadding}
|
||||
{styleMinHeight}
|
||||
bind:selectionEnd
|
||||
bind:selectionStart
|
||||
onpaste={handlePaste}
|
||||
{focus}
|
||||
submit={() => submit({ comment: body, embeds })}
|
||||
bind:value={body}
|
||||
{placeholder} />
|
||||
{#if !hints.isDismissed("markdown")}
|
||||
<div class="markdown-hint txt-body-s-regular">
|
||||
<Icon
|
||||
name="markdown"
|
||||
styleDisplay="inline"
|
||||
styleVerticalAlign="text-top" />
|
||||
Markdown is supported
|
||||
<button
|
||||
type="button"
|
||||
class="markdown-hint-dismiss"
|
||||
title="Don't show again"
|
||||
onclick={() => hints.dismiss("markdown")}>
|
||||
Hide
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<Textarea
|
||||
size={textAreaSize}
|
||||
styleAlignItems="flex-start"
|
||||
{draggingOver}
|
||||
{borderVariant}
|
||||
{stylePadding}
|
||||
{styleMinHeight}
|
||||
bind:selectionEnd
|
||||
bind:selectionStart
|
||||
onpaste={handlePaste}
|
||||
{focus}
|
||||
submit={() => submit({ comment: body, embeds })}
|
||||
bind:value={body}
|
||||
{placeholder} />
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
{@render belowTextarea?.()}
|
||||
{#if !hideDiscard || body.trim() !== ""}
|
||||
<div class="actions">
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import useLocalStorage from "@app/lib/useLocalStorage.svelte";
|
||||
|
||||
// One-off tips that can be dismissed permanently. Kept in a single list so
|
||||
// settings can offer to bring all of them back.
|
||||
export type HintId = "markdown";
|
||||
|
||||
const storage = useLocalStorage("dismissedHints", z.array(z.string()), []);
|
||||
|
||||
export const hints = {
|
||||
get dismissedCount(): number {
|
||||
return storage.value.length;
|
||||
},
|
||||
|
||||
isDismissed(id: HintId): boolean {
|
||||
return storage.value.includes(id);
|
||||
},
|
||||
|
||||
dismiss(id: HintId) {
|
||||
if (!storage.value.includes(id)) {
|
||||
storage.value = [...storage.value, id];
|
||||
}
|
||||
},
|
||||
|
||||
resetAll() {
|
||||
storage.value = [];
|
||||
},
|
||||
};
|
||||
@@ -1,6 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { hints } from "@app/lib/hints";
|
||||
import { hide } from "@app/lib/modal";
|
||||
import { updateChecker } from "@app/lib/updateChecker.svelte";
|
||||
import { pluralize } from "@app/lib/utils";
|
||||
|
||||
import AnnounceSwitch from "@app/components/AnnounceSwitch.svelte";
|
||||
import BadgeCounterSwitch from "@app/components/BadgeCounterSwitch.svelte";
|
||||
@@ -130,6 +132,22 @@
|
||||
disable={updateChecker.disable}
|
||||
enable={updateChecker.enable} />
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="row-label">
|
||||
<span class="row-title">Hidden hints</span>
|
||||
<span class="row-description">
|
||||
{hints.dismissedCount === 0
|
||||
? "You haven't hidden any hints"
|
||||
: `Show the ${hints.dismissedCount} ${pluralize("hint", hints.dismissedCount)} you've hidden again`}
|
||||
</span>
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
disabled={hints.dismissedCount === 0}
|
||||
onclick={() => hints.resetAll()}>
|
||||
Reset
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer">
|
||||
{#if updateChecker.currentVersion}
|
||||
|
||||
Reference in New Issue
Block a user