Bring back the old nav (#100)

* Bring back the old nav

* Added bool to settings

* settings wireup

* Fixy fix

* fix create btn

---------

Co-authored-by: thesuzerain <wverchere@gmail.com>
Co-authored-by: Jai A <jaiagr+gpg@pm.me>
This commit is contained in:
Adrian O.V
2023-05-05 18:37:23 -04:00
committed by GitHub
parent edd9f28081
commit c79d5c32a6
11 changed files with 202 additions and 87 deletions

View File

@@ -361,7 +361,6 @@ pub async fn infer_data_from_files(
update_version: update_versions update_version: update_versions
.get(&hash) .get(&hash)
.map(|val| Box::new(val.clone())), .map(|val| Box::new(val.clone())),
incompatible: !version.loaders.contains( incompatible: !version.loaders.contains(
&profile &profile
.metadata .metadata

View File

@@ -24,6 +24,7 @@ pub struct Settings {
pub hooks: Hooks, pub hooks: Hooks,
pub max_concurrent_downloads: usize, pub max_concurrent_downloads: usize,
pub version: u32, pub version: u32,
pub collapsed_navigation: bool,
} }
impl Default for Settings { impl Default for Settings {
@@ -39,6 +40,7 @@ impl Default for Settings {
hooks: Hooks::default(), hooks: Hooks::default(),
max_concurrent_downloads: 64, max_concurrent_downloads: 64,
version: CURRENT_FORMAT_VERSION, version: CURRENT_FORMAT_VERSION,
collapsed_navigation: false,
} }
} }
} }

View File

@@ -16,6 +16,7 @@ pub struct FrontendSettings {
pub hooks: Hooks, pub hooks: Hooks,
pub max_concurrent_downloads: usize, pub max_concurrent_downloads: usize,
pub version: u32, pub version: u32,
pub collapsed_navigation: bool,
} }
// Get full settings // Get full settings
@@ -39,6 +40,7 @@ pub async fn settings_get() -> Result<FrontendSettings> {
hooks: backend_settings.hooks, hooks: backend_settings.hooks,
max_concurrent_downloads: backend_settings.max_concurrent_downloads, max_concurrent_downloads: backend_settings.max_concurrent_downloads,
version: backend_settings.version, version: backend_settings.version,
collapsed_navigation: backend_settings.collapsed_navigation,
}; };
Ok(frontend_settings) Ok(frontend_settings)
} }
@@ -76,6 +78,7 @@ pub async fn settings_set(settings: FrontendSettings) -> Result<()> {
hooks: settings.hooks, hooks: settings.hooks,
max_concurrent_downloads: settings.max_concurrent_downloads, max_concurrent_downloads: settings.max_concurrent_downloads,
version: settings.version, version: settings.version,
collapsed_navigation: settings.collapsed_navigation,
}; };
settings::set(backend_settings).await?; settings::set(backend_settings).await?;
Ok(()) Ok(())

View File

@@ -1,7 +1,7 @@
<script setup> <script setup>
import { ref, onMounted } from 'vue' import { ref, onMounted } from 'vue'
import { RouterView, RouterLink } from 'vue-router' import { RouterView, RouterLink } from 'vue-router'
import { HomeIcon, SearchIcon, LibraryIcon, PlusIcon, SettingsIcon } from 'omorphia' import { HomeIcon, SearchIcon, LibraryIcon, PlusIcon, SettingsIcon, Button } from 'omorphia'
import { useTheming } from '@/store/state' import { useTheming } from '@/store/state'
import AccountsCard from '@/components/ui/AccountsCard.vue' import AccountsCard from '@/components/ui/AccountsCard.vue'
import InstanceCreationModal from '@/components/ui/InstanceCreationModal.vue' import InstanceCreationModal from '@/components/ui/InstanceCreationModal.vue'
@@ -13,8 +13,9 @@ import RunningAppBar from '@/components/ui/RunningAppBar.vue'
const themeStore = useTheming() const themeStore = useTheming()
onMounted(async () => { onMounted(async () => {
const { theme } = await get() const { settings, collapsed_navigation } = await get()
themeStore.setThemeState(theme) themeStore.setThemeState(settings)
themeStore.collapsedNavigation = collapsed_navigation
}) })
const installedMods = ref(0) const installedMods = ref(0)
@@ -30,33 +31,81 @@ list().then(
<template> <template>
<div class="container"> <div class="container">
<div class="nav-container"> <div class="nav-container" :class="{ expanded: !themeStore.collapsedNavigation }">
<div class="nav-section"> <div class="nav-section">
<suspense> <suspense>
<AccountsCard ref="accounts" /> <AccountsCard ref="accounts" :expanded="!themeStore.collapsedNavigation" />
</suspense> </suspense>
<div class="pages-list"> <div class="pages-list">
<RouterLink to="/" class="button-base nav-button"><HomeIcon /></RouterLink> <RouterLink
<RouterLink to="/browse" class="button-base nav-button"> <SearchIcon /></RouterLink> to="/"
<RouterLink to="/library" class="button-base nav-button"> <LibraryIcon /></RouterLink> class="btn"
<button :class="{
'icon-only': themeStore.collapsedNavigation,
'collapsed-button': themeStore.collapsedNavigation,
'expanded-button': !themeStore.collapsedNavigation,
}"
>
<HomeIcon />
<span v-if="!themeStore.collapsedNavigation">Home</span>
</RouterLink>
<RouterLink
to="/browse"
class="btn"
:class="{
'icon-only': themeStore.collapsedNavigation,
'collapsed-button': themeStore.collapsedNavigation,
'expanded-button': !themeStore.collapsedNavigation,
}"
>
<SearchIcon />
<span v-if="!themeStore.collapsedNavigation">Browse</span>
</RouterLink>
<RouterLink
to="/library"
class="btn"
:class="{
'icon-only': themeStore.collapsedNavigation,
'collapsed-button': themeStore.collapsedNavigation,
'expanded-button': !themeStore.collapsedNavigation,
}"
>
<LibraryIcon />
<span v-if="!themeStore.collapsedNavigation">Library</span>
</RouterLink>
<Button
color="primary" color="primary"
class="button-base primary nav-button" :class="{
icon-only 'icon-only': themeStore.collapsedNavigation,
'collapsed-button': themeStore.collapsedNavigation,
'expanded-button': !themeStore.collapsedNavigation,
}"
@click="() => $refs.installationModal.show()" @click="() => $refs.installationModal.show()"
> >
<PlusIcon /> <PlusIcon />
</button> <span v-if="!themeStore.collapsedNavigation" class="no-wrap">New Instance</span>
</Button>
<Suspense> <Suspense>
<InstanceCreationModal ref="installationModal" /> <InstanceCreationModal ref="installationModal" />
</Suspense> </Suspense>
</div> </div>
</div> </div>
<div class="settings pages-list"> <div class="settings pages-list">
<RouterLink to="/settings" class="button-base nav-button"><SettingsIcon /></RouterLink> <RouterLink
to="/settings"
class="btn"
:class="{
'icon-only': themeStore.collapsedNavigation,
'collapsed-button': themeStore.collapsedNavigation,
'expanded-button': !themeStore.collapsedNavigation,
}"
>
<SettingsIcon />
<span v-if="!themeStore.collapsedNavigation">Settings</span>
</RouterLink>
</div> </div>
</div> </div>
<div class="view"> <div class="view" :class="{ expanded: !themeStore.collapsedNavigation }">
<div class="appbar"> <div class="appbar">
<section class="navigation-controls"> <section class="navigation-controls">
<Breadcrumbs /> <Breadcrumbs />
@@ -86,6 +135,10 @@ list().then(
.view { .view {
width: calc(100% - 5rem); width: calc(100% - 5rem);
&.expanded {
width: calc(100% - 12rem);
}
.appbar { .appbar {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
@@ -171,12 +224,18 @@ list().then(
box-shadow: var(--shadow-inset-sm), var(--shadow-floating); box-shadow: var(--shadow-inset-sm), var(--shadow-floating);
padding: 1rem; padding: 1rem;
background: var(--color-raised-bg); background: var(--color-raised-bg);
&.expanded {
width: 13rem;
max-width: 13rem;
min-width: 13rem;
}
} }
.pages-list { .pages-list {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: flex-start;
justify-content: flex-start; justify-content: flex-start;
width: 100%; width: 100%;
gap: 0.5rem; gap: 0.5rem;
@@ -184,8 +243,6 @@ list().then(
a { a {
display: flex; display: flex;
align-items: center; align-items: center;
font-size: 0.9rem;
font-weight: 400;
word-spacing: 3px; word-spacing: 3px;
background: inherit; background: inherit;
transition: all ease-in-out 0.1s; transition: all ease-in-out 0.1s;
@@ -194,6 +251,7 @@ list().then(
&.router-link-active { &.router-link-active {
color: var(--color-contrast); color: var(--color-contrast);
background: var(--color-button-bg); background: var(--color-button-bg);
box-shadow: var(--shadow-floating);
} }
&:hover { &:hover {
@@ -203,20 +261,6 @@ list().then(
text-decoration: none; text-decoration: none;
} }
} }
}
.nav-button {
height: 3rem;
width: 3rem;
padding: 0.75rem;
border-radius: var(--radius-md);
svg {
width: 1.5rem;
height: 1.5rem;
max-width: 1.5rem;
max-height: 1.5rem;
}
&.primary { &.primary {
color: var(--color-accent-contrast); color: var(--color-accent-contrast);
@@ -224,6 +268,26 @@ list().then(
} }
} }
.collapsed-button {
height: 3rem !important;
width: 3rem !important;
padding: 0.75rem;
border-radius: var(--radius-md);
box-shadow: none;
svg {
width: 1.5rem !important;
height: 1.5rem !important;
max-width: 1.5rem !important;
max-height: 1.5rem !important;
}
}
.expanded-button {
width: 100%;
padding: var(--gap-md) var(--gap-lg);
}
.instance-list { .instance-list {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@@ -245,38 +309,6 @@ list().then(
} }
} }
.add-instance-btn {
background-color: var(--color-bg);
font-size: 0.9rem;
margin-right: 0.6rem;
svg {
background-color: var(--color-green);
width: 1.5rem;
height: 1.5rem;
color: var(--color-accent-contrast);
border-radius: var(--radius-xs);
}
}
.settings {
svg {
color: var(--color-base) !important;
}
a {
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: center;
gap: 1rem;
&:hover {
text-decoration: none;
}
}
}
.user-section { .user-section {
display: flex; display: flex;
justify-content: flex-start; justify-content: flex-start;
@@ -294,14 +326,12 @@ list().then(
.username { .username {
margin-bottom: 0.3rem; margin-bottom: 0.3rem;
font-size: 1.1rem;
font-weight: 400; font-weight: 400;
line-height: 1.25rem; line-height: 1.25rem;
color: var(--color-contrast); color: var(--color-contrast);
} }
a { a {
font-size: 0.75rem;
font-weight: 400; font-weight: 400;
color: var(--color-secondary); color: var(--color-secondary);
} }

View File

@@ -4,3 +4,4 @@ export { default as BrowseIcon } from './folder-search.svg'
export { default as LoginIcon } from './log-in.svg' export { default as LoginIcon } from './log-in.svg'
export { default as StopIcon } from './stop-circle.svg' export { default as StopIcon } from './stop-circle.svg'
export { default as TerminalIcon } from './terminal-square.svg' export { default as TerminalIcon } from './terminal-square.svg'
export { default as UsersIcon } from './users.svg'

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-users"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"></path><circle cx="9" cy="7" r="4"></circle><path d="M22 21v-2a4 4 0 0 0-3-3.87"></path><path d="M16 3.13a4 4 0 0 1 0 7.75"></path></svg>

After

Width:  |  Height:  |  Size: 398 B

View File

@@ -22,6 +22,12 @@
white-space: nowrap; white-space: nowrap;
} }
.no-select {
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
a { a {
color: var(--color-link); color: var(--color-link);
text-decoration: none; text-decoration: none;

View File

@@ -1,13 +1,23 @@
<template> <template>
<Avatar <div
ref="avatar" ref="button"
class="button-base" class="button-base avatar-button"
size="sm" :class="{ expanded: expanded }"
:src="selectedAccount?.profile_picture ?? ''"
@click="toggle()" @click="toggle()"
/> >
<Avatar :size="expanded ? 'xs' : 'sm'" :src="selectedAccount?.profile_picture ?? ''" />
<div v-show="expanded" class="avatar-text">
<div class="text no-select">
{{ selectedAccount.username }}
</div>
<p class="no-select">
<UsersIcon />
Accounts
</p>
</div>
</div>
<transition name="fade"> <transition name="fade">
<Card v-if="showCard" ref="card" class="account-card"> <Card v-if="showCard" ref="card" class="account-card" :class="{ expanded: expanded }">
<div v-if="selectedAccount" class="selected account"> <div v-if="selectedAccount" class="selected account">
<Avatar size="xs" :src="selectedAccount.profile_picture" /> <Avatar size="xs" :src="selectedAccount.profile_picture" />
<div> <div>
@@ -15,7 +25,7 @@
<p>Selected</p> <p>Selected</p>
</div> </div>
<Button icon-only color="raised" @click="logout(selectedAccount.id)"> <Button icon-only color="raised" @click="logout(selectedAccount.id)">
<LogOutIcon /> <XIcon />
</Button> </Button>
</div> </div>
<div v-else class="logged-out account"> <div v-else class="logged-out account">
@@ -31,7 +41,7 @@
<p>{{ account.username }}</p> <p>{{ account.username }}</p>
</Button> </Button>
<Button icon-only @click="logout(account.id)"> <Button icon-only @click="logout(account.id)">
<LogOutIcon /> <XIcon />
</Button> </Button>
</div> </div>
</div> </div>
@@ -44,9 +54,9 @@
</template> </template>
<script setup> <script setup>
import { Avatar, Button, Card, PlusIcon, LogOutIcon } from 'omorphia' import { Avatar, Button, Card, PlusIcon, XIcon } from 'omorphia'
import { LoginIcon } from '@/assets/icons' import { LoginIcon, UsersIcon } from '@/assets/icons'
import { ref, computed, onMounted, onBeforeUnmount } from 'vue' import { ref, defineProps, computed, onMounted, onBeforeUnmount } from 'vue'
import { import {
users, users,
remove_user, remove_user,
@@ -56,6 +66,13 @@ import {
import { get, set } from '@/helpers/settings' import { get, set } from '@/helpers/settings'
import { WebviewWindow } from '@tauri-apps/api/window' import { WebviewWindow } from '@tauri-apps/api/window'
defineProps({
expanded: {
type: Boolean,
required: true,
},
})
const settings = ref(await get()) const settings = ref(await get())
const appendProfiles = (accounts) => { const appendProfiles = (accounts) => {
@@ -86,7 +103,7 @@ const refreshValues = async () => {
let showCard = ref(false) let showCard = ref(false)
let card = ref(null) let card = ref(null)
let avatar = ref(null) let button = ref(null)
const setAccount = async (account) => { const setAccount = async (account) => {
settings.value.default_user = account.id settings.value.default_user = account.id
@@ -95,9 +112,7 @@ const setAccount = async (account) => {
} }
const login = async () => { const login = async () => {
console.log('login process')
const url = await authenticate_begin_flow() const url = await authenticate_begin_flow()
console.log(url)
const window = new WebviewWindow('loginWindow', { const window = new WebviewWindow('loginWindow', {
url: url, url: url,
@@ -128,15 +143,15 @@ const logout = async (id) => {
const toggle = () => { const toggle = () => {
showCard.value = !showCard.value showCard.value = !showCard.value
console.log('toggled')
} }
const handleClickOutside = (event) => { const handleClickOutside = (event) => {
const elements = document.elementsFromPoint(event.clientX, event.clientY)
if ( if (
card.value && card.value &&
avatar.value.$el !== event.target &&
card.value.$el !== event.target && card.value.$el !== event.target &&
!document.elementsFromPoint(event.clientX, event.clientY).includes(card.value.$el) !elements.includes(card.value.$el) &&
!button.value.contains(event.target)
) { ) {
showCard.value = false showCard.value = false
} }
@@ -177,8 +192,8 @@ onBeforeUnmount(() => {
position: absolute; position: absolute;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
top: 0; top: 0.5rem;
left: 5rem; left: 5.5rem;
z-index: 100; z-index: 100;
gap: 0.5rem; gap: 0.5rem;
padding: 1rem; padding: 1rem;
@@ -191,6 +206,10 @@ onBeforeUnmount(() => {
&.hidden { &.hidden {
display: none; display: none;
} }
&.expanded {
left: 13.5rem;
}
} }
.accounts-title { .accounts-title {
@@ -238,4 +257,33 @@ onBeforeUnmount(() => {
.fade-leave-to { .fade-leave-to {
opacity: 0; opacity: 0;
} }
.avatar-button {
display: flex;
align-items: center;
gap: 0.5rem;
color: var(--color-base);
background-color: var(--color-bg);
border-radius: var(--radius-md);
box-shadow: none;
width: 100%;
text-align: left;
&.expanded {
padding: 1rem;
}
}
.avatar-text {
margin: auto 0 auto 0.25rem;
display: flex;
flex-direction: column;
}
.text {
width: 6rem;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style> </style>

View File

@@ -18,6 +18,7 @@ Settings {
"hooks": Hooks, "hooks": Hooks,
"max_concurrent_downloads": uint, "max_concurrent_downloads": uint,
"version": u32, "version": u32,
"collapsed_navigation": bool,
} }
Memorysettings { Memorysettings {

View File

@@ -12,6 +12,7 @@ import {
XIcon, XIcon,
PlusIcon, PlusIcon,
AnimatedLogo, AnimatedLogo,
Toggle,
} from 'omorphia' } from 'omorphia'
import { BrowseIcon } from '@/assets/icons' import { BrowseIcon } from '@/assets/icons'
import { useTheming } from '@/store/state' import { useTheming } from '@/store/state'
@@ -46,6 +47,12 @@ const handleTheme = async (e) => {
await set(settings.value) await set(settings.value)
} }
const handleCollapse = async (e) => {
themeStore.collapsedNavigation = e
settings.value.collapsed_navigation = themeStore.collapsedNavigation
await set(settings.value)
}
const loadJavaModal = async (version) => { const loadJavaModal = async (version) => {
if (version === 17) chosenInstallOptions.value = await find_jre_17_jres() if (version === 17) chosenInstallOptions.value = await find_jre_17_jres()
else if (version === 8) chosenInstallOptions.value = await find_jre_8_jres() else if (version === 8) chosenInstallOptions.value = await find_jre_8_jres()
@@ -175,6 +182,17 @@ const setJavaInstall = (javaInstall) => {
@change="handleTheme" @change="handleTheme"
/> />
</div> </div>
<div class="toggle-setting">
<div class="description">
<h3>Collapsed navigation mode</h3>
<p>Change the style of the side navigation bar</p>
</div>
<Toggle
:model-value="themeStore.collapsedNavigation"
:checked="themeStore.collapsedNavigation"
@update:model-value="(value) => handleCollapse(value)"
/>
</div>
</Card> </Card>
<Card class="settings-card"> <Card class="settings-card">
<h2 class="settings-title">Java</h2> <h2 class="settings-title">Java</h2>
@@ -365,6 +383,7 @@ const setJavaInstall = (javaInstall) => {
margin: 1rem; margin: 1rem;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 1rem;
} }
.theming { .theming {

View File

@@ -1,7 +1,12 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
export const useTheming = defineStore('themeStore', { export const useTheming = defineStore('themeStore', {
state: () => ({ themeOptions: ['light', 'dark'], selectedTheme: 'dark', darkTheme: true }), state: () => ({
themeOptions: ['light', 'dark'],
collapsedNavigation: false,
selectedTheme: 'dark',
darkTheme: true,
}),
actions: { actions: {
setThemeState(newTheme) { setThemeState(newTheme) {
if (this.themeOptions.includes(newTheme)) this.selectedTheme = newTheme if (this.themeOptions.includes(newTheme)) this.selectedTheme = newTheme