Spaces:
Runtime error
Runtime error
File size: 4,945 Bytes
faca43f d54ea4b faca43f d54ea4b faca43f d54ea4b faca43f d54ea4b faca43f d54ea4b faca43f d54ea4b faca43f d54ea4b faca43f d54ea4b faca43f d54ea4b faca43f d54ea4b faca43f d54ea4b faca43f d54ea4b faca43f d54ea4b faca43f d54ea4b faca43f d54ea4b faca43f d54ea4b faca43f d54ea4b faca43f d54ea4b faca43f d54ea4b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
<script lang="ts">
import { base } from "$app/paths";
import { createEventDispatcher } from "svelte";
import Login from "$lib/components/Login.svelte";
import Logo from "$lib/components/icons/Logo.svelte";
import { page } from "$app/stores";
import { PUBLIC_APP_NAME, PUBLIC_ORIGIN, PUBLIC_APP_ASSETS } from "$env/static/public";
import NavConversationItem from "./NavConversationItem.svelte";
import type { LayoutData } from "../../routes/$types";
import { api_key_writable, is_logged_writable, is_magic_writable, email_addr_writable } from "../../routes/LayoutWritable";
const dispatch = createEventDispatcher<{
shareConversation: { id: string; title: string };
clickSettings: void;
clickLogout: void;
}>();
export let conversations: Array<{
id: string;
title: string;
}> = [];
export let canLogin: boolean;
export let signedIn: boolean;
export let user: LayoutData["user"];
export let loginModalVisible;
let isSubMenuOpen: boolean = false;
let magic = false;
let isLogged = false;
is_magic_writable.subscribe((val) => {
magic = val;
})
is_logged_writable.subscribe((val) => {
isLogged = val;
})
let email_addr = ""
email_addr_writable.subscribe((val) => {
email_addr = val
})
function toggleSubMenu() {
isSubMenuOpen = !isSubMenuOpen;
}
async function logoutSubmit(event: { preventDefault: () => void }) {
event.preventDefault();
try {
const response = await fetch("https://cloud.mithrilsecurity.io/api/auth/logout", {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
},
});
if (response.ok) {
// Handle a successful response
console.log("Logout successful");
signedIn = false;
is_logged_writable.set(false);
api_key_writable.set("");
email_addr_writable.set("");
} else {
// Handle errors
console.error("Logout failed");
}
} catch (error) {
// Handle network errors
console.error("Network error", error);
}
}
function handleKeyDown(event: { key: string; }) {
if (event.key === 'Enter') {
toggleSubMenu();
}
}
function handleTempClick() {
loginModalVisible = true;
is_magic_writable.set(false);
}
</script>
<!-- top left corner - remove from class bg-[#141c2a] -->
<div class="bg-[#142343] sticky top-0 flex flex-none items-center justify-between px-3 py-5 max-sm:pt-0">
<a class="flex items-center rounded-xl text-lg font-semibold" href="{PUBLIC_ORIGIN}{base}/">
<Logo classNames="mr-1" />
<div class = "pl-2 text-white"> {PUBLIC_APP_NAME} </div>
</a>
<a
href={`${base}/`}
class="flex rounded-lg border bg-white px-2 py-0.5 text-center shadow-sm hover:shadow-none dark:border-mithril-border dark:bg-sidebar"
>
New Chat
</a>
</div>
<!-- left side bar
style = "background-color: #141c2a !important;"
-->
<div
class="bg-[#142343] scrollbar-custom flex flex-col gap-1 overflow-y-auto px-3 pb-3 pt-2 dark:from-gray-800/30"
>
{#each conversations as conv (conv.id)}
<div class="py-1">
<NavConversationItem on:editConversationTitle on:deleteConversation {conv}/>
</div>
{/each}
</div>
<!-- <div class="display position relative inline-block bg-[#142343] flex justify-center items-center pb-4">
<div
class="rounded-2xl text-center bg-[#0d1830] flex items-center justify-center group h-11 -lg text-white w-[96%] hover:bg-gray-600 font-semibold"
on:click={toggleSubMenu}
on:keydown={handleKeyDown}
>
{email_addr.length > 0 ? email_addr : "Not logged in"}
</div>
{#if isSubMenuOpen}
<script type="text/javascript">
document.getElementById("submenu").style.display = "block";
</script>
<div class="justify-center items-center rounded-2xl {isSubMenuOpen ? 'open' : ''}" style="position: absolute; bottom: 100%; width: 96%; background-color: #0d1830 !important;">
<div>
<button
on:click={() => dispatch("clickSettings")}
type="button"
class="px-8 block py-3 text-center h-11 text-white hover:bg-gray-600 rounded-2xl" style="width: 100%;"
>
Settings
</button>
<div class="flex justify-center" style="position: relative;">
<a href="https://1qdag6eehid.typeform.com/to/EFrGfL1u" target="_blank" rel="noopener noreferrer"
class="px-8 block py-3 text-center h-11 text-white hover:bg-gray-600 rounded-2xl w-[100%]">
Give Feedback
</a>
<img
class="absolute max-w-[3%] md:max-w-[6%] bottom-[32%] right-[35%] md:right-[20%]"
alt="redirect to page in new tab icon"
src="{PUBLIC_ORIGIN || $page.url.origin}{base}/{PUBLIC_APP_ASSETS}/link.png"
title="link to open new page"
/>
</div>
<div class="justify flex items-center justify-center">
<p class="border-t border-mithril-border w-[80%]"></p>
</div>
<button
on:click={logoutSubmit}
type="button"
class="px-8 py-3 text-center h-11 text-white hover:bg-gray-600 rounded-2xl"
style="width: 100%;"
>
<p class="">Log out</p>
</button>
</div>
</div>
{/if} -->
<!-- </div> --> |