Improved key success message layout for mobile, using global 'now' to prevent hydration mismatches.

This commit is contained in:
DebaucheryLibrarian 2024-08-31 22:15:39 +02:00
parent 2882bd59e9
commit 6e130dd96e
3 changed files with 29 additions and 16 deletions

View File

@ -258,7 +258,7 @@ const theme = ref(pageContext.env.theme);
const user = pageContext.user; const user = pageContext.user;
const primaryStash = pageContext.assets?.primaryStash; const primaryStash = pageContext.assets?.primaryStash;
const unseen = ref(pageContext.meta.unseenNotifications); const unseen = ref(pageContext.assets?.unseenNotifications);
const query = ref(pageContext.urlParsed.search.q || ''); const query = ref(pageContext.urlParsed.search.q || '');
const allowLogin = pageContext.env.allowLogin; const allowLogin = pageContext.env.allowLogin;
const searchFocused = ref(false); const searchFocused = ref(false);

View File

@ -22,14 +22,13 @@
v-if="newKey" v-if="newKey"
class="newkey" class="newkey"
> >
<p class="key-info"> <p class="key-info">Successfully generated key with identifier <strong class="newkey-identifier ellipsis">{{ newKey.identifier }}</strong>:</p>
Your new key identified by <strong>{{ newKey.identifier }}</strong> is
<input <input
:value="newKey.key" :value="newKey.key"
class="input" class="input ellipsis"
@click="copyKey" @click="copyKey"
> >
</p>
<p class="key-info">Please store this key securely, you will <strong>not</strong> be able to retrieve it later. If you lose it, you must generate a new key.</p> <p class="key-info">Please store this key securely, you will <strong>not</strong> be able to retrieve it later. If you lose it, you must generate a new key.</p>
</div> </div>
@ -61,7 +60,7 @@
<time <time
v-tooltip="format(key.createdAt, 'yyyy-MM-dd hh:mm:ss')" v-tooltip="format(key.createdAt, 'yyyy-MM-dd hh:mm:ss')"
:datetime="key.createdAt.toISOString()" :datetime="key.createdAt.toISOString()"
>{{ formatDistanceToNowStrict(key.createdAt) }} ago</time> >{{ formatDistanceStrict(key.createdAt, now) }} ago</time>
</span> </span>
<span class="key-value key-used"> <span class="key-value key-used">
@ -71,7 +70,7 @@
<time <time
v-tooltip="`${key.lastUsedIp} at ${format(key.lastUsedAt, 'yyyy-MM-dd hh:mm:ss')}`" v-tooltip="`${key.lastUsedIp} at ${format(key.lastUsedAt, 'yyyy-MM-dd hh:mm:ss')}`"
:datetime="key.lastUsedAt.toISOString()" :datetime="key.lastUsedAt.toISOString()"
>{{ formatDistanceToNowStrict(key.lastUsedAt) }} ago</time> >{{ formatDistanceStrict(key.lastUsedAt, now) }} ago</time>
</template> </template>
<template v-else>Never</template> <template v-else>Never</template>
@ -97,12 +96,13 @@
<script setup> <script setup>
import { ref, inject } from 'vue'; import { ref, inject } from 'vue';
import { format, formatDistanceToNowStrict } from 'date-fns'; import { format, formatDistanceStrict } from 'date-fns';
import { get, post, del } from '#/src/api.js'; import { get, post, del } from '#/src/api.js';
import events from '#/src/events.js'; import events from '#/src/events.js';
const pageContext = inject('pageContext'); const pageContext = inject('pageContext');
const now = pageContext.meta.now;
const user = pageContext.user; const user = pageContext.user;
const keys = ref(pageContext.pageProps.keys); const keys = ref(pageContext.pageProps.keys);
const newKey = ref(null); const newKey = ref(null);
@ -242,8 +242,10 @@ function copyKey(event) {
} }
.newkey { .newkey {
max-width: 100%;
display: inline-block; display: inline-block;
padding: .5rem 1rem; box-sizing: border-box;
padding: .5rem .75rem;
margin-bottom: 1rem; margin-bottom: 1rem;
background: var(--enabled-background); background: var(--enabled-background);
border: solid 1px var(--success); border: solid 1px var(--success);
@ -252,13 +254,23 @@ function copyKey(event) {
.input { .input {
width: 24rem; width: 24rem;
padding: .25rem .75rem; max-width: 100%;
padding: .25rem .5rem;
margin-bottom: .5rem;
font-weight: bold; font-weight: bold;
} }
} }
.newkey-identifier {
white-space: nowrap;
}
.key-info { .key-info {
margin: 0 0 .5rem 0; margin: 0;
&:not(:last-child) {
margin-bottom: .25rem;
}
} }
.headers { .headers {

View File

@ -28,6 +28,7 @@ export default async function mainHandler(req, res, next) {
stashes, stashes,
primaryStash: stashes.find((stash) => stash.isPrimary), primaryStash: stashes.find((stash) => stash.isPrimary),
templates, templates,
unseenNotifications,
} : null, } : null,
env: { env: {
theme: req.cookies.theme || req.headers['sec-ch-prefers-color-scheme'] || 'light', theme: req.cookies.theme || req.headers['sec-ch-prefers-color-scheme'] || 'light',
@ -41,7 +42,7 @@ export default async function mainHandler(req, res, next) {
links: config.links, links: config.links,
}, },
meta: { meta: {
unseenNotifications, now: new Date().toISOString(),
}, },
}; };