Skip to content

Commit

Permalink
fixed requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thesuzerain committed Jul 18, 2023
1 parent a3cc267 commit 94f8856
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 106 deletions.
22 changes: 0 additions & 22 deletions theseus/src/api/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,6 @@ pub async fn get(
Ok(profile)
}

/// Gets all projects version metadata for a profile
/// Allows loading metadata without loading all project data
#[tracing::instrument]
pub async fn get_projects_metadata(
path: &Path,
) -> crate::Result<Option<HashMap<PathBuf, ProjectMetadata>>> {
let state = State::get().await?;
let profiles = state.profiles.read().await;
let profile = profiles.0.get(path).cloned();
if let Some(profile) = profile {
Ok(Some(
profile
.projects
.into_iter()
.map(|(k, v)| (k, v.metadata))
.collect(),
))
} else {
Ok(None)
}
}

/// Edit a profile using a given asynchronous closure
pub async fn edit<Fut>(
path: &Path,
Expand Down
11 changes: 0 additions & 11 deletions theseus_gui/src-tauri/src/api/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
.invoke_handler(tauri::generate_handler![
profile_remove,
profile_get,
profile_get_projects_metadata,
profile_get_optimal_jre_key,
profile_list,
profile_check_installed,
Expand Down Expand Up @@ -53,16 +52,6 @@ pub async fn profile_get(
Ok(res)
}

// Get a profile's projects metadata
// Designed to access metadata without needing to load all project data
// invoke('plugin:profile|profile_get_projects_metadata',path)
#[tauri::command]
pub async fn profile_get_projects_metadata(
path: &Path,
) -> Result<Option<HashMap<PathBuf, ProjectMetadata>>> {
let res = profile::get_projects_metadata(path).await?;
Ok(res)
}
// Get optimal java version from profile
#[tauri::command]
pub async fn profile_get_optimal_jre_key(
Expand Down
51 changes: 10 additions & 41 deletions theseus_gui/src/components/ui/AccountsCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
ref="button"
class="button-base avatar-button"
:class="{ expanded: mode === 'expanded' }"
@click="toggleShow()"
@click="showCard = !showCard"
>
<Avatar
:size="mode === 'expanded' ? 'xs' : 'sm'"
Expand Down Expand Up @@ -33,23 +33,7 @@
<h4>{{ selectedAccount.username }}</h4>
<p>Selected</p>
</div>

<Button
v-if="showLogoutWarning(selectedAccount.id)"
v-tooltip="'Log out'"
icon-only
color="highlight"
@click="logout(selectedAccount.id)"
>
<TrashIcon />
</Button>
<Button
v-else
v-tooltip="'Log out'"
icon-only
color="raised"
@click="logout(selectedAccount.id)"
>
<Button v-tooltip="'Log out'" icon-only color="raised" @click="logout(selectedAccount.id)">
<TrashIcon />
</Button>
</div>
Expand All @@ -66,8 +50,7 @@
<p>{{ account.username }}</p>
</Button>
<Button v-tooltip="'Log out'" icon-only @click="logout(account.id)">
<SwapIcon v-if="showLogoutWarning(account.id)" />
<TrashIcon v-else />
<TrashIcon />
</Button>
</div>
</div>
Expand All @@ -92,7 +75,6 @@ import { get, set } from '@/helpers/settings'
import { WebviewWindow } from '@tauri-apps/api/window'
import { handleError } from '@/store/state.js'
import mixpanel from 'mixpanel-browser'
import { SwapIcon } from '@/assets/icons'
defineProps({
mode: {
Expand All @@ -105,15 +87,10 @@ defineProps({
const emit = defineEmits(['change'])
const settings = ref({})
const logoutWarning = ref({})
const showLogoutWarning = (id) => {
return logoutWarning.value[id] == true
}
const accounts = ref([])
async function refreshValues() {
settings.value = await get().catch(handleError)
accounts.value = await users().catch(handleError)
logoutWarning.value = {}
}
defineExpose({
refreshValues,
Expand Down Expand Up @@ -150,26 +127,18 @@ async function login() {
}
const logout = async (id) => {
if (!logoutWarning.value[id]) {
logoutWarning.value[id] = true
} else {
await remove_user(id).catch(handleError)
await remove_user(id).catch(handleError)
await refreshValues()
if (!selectedAccount.value && accounts.value.length > 0) {
await setAccount(accounts.value[0])
await refreshValues()
if (!selectedAccount.value && accounts.value.length > 0) {
await setAccount(accounts.value[0])
await refreshValues()
} else {
emit('change')
}
mixpanel.track('AccountLogOut')
} else {
emit('change')
}
mixpanel.track('AccountLogOut')
}
let showCard = ref(false)
const toggleShow = () => {
showCard.value = !showCard.value
logoutWarning.value = {}
}
let card = ref(null)
let button = ref(null)
const handleClickOutside = (event) => {
Expand Down
6 changes: 0 additions & 6 deletions theseus_gui/src/helpers/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ export async function get(path, clearProjects) {
return await invoke('plugin:profile|profile_get', { path, clearProjects })
}

// Get a profile's metadata
// Returns an hash of project path => ProfileMetadata
export async function get_projects_metadata(path) {
return await invoke('plugin:profile|profile_get_projects_metadata', { path })
}

// Get optimal java version from profile
// Returns a java version
export async function get_optimal_jre_key(path) {
Expand Down
14 changes: 0 additions & 14 deletions theseus_gui/src/pages/Browse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -267,22 +267,8 @@ async function onSearchChange(newPageNumber) {
const searchWrapper = ref(null)
async function onSearchChangeToTop(newPageNumber) {
console.log('onSearchChangeToTop')
await onSearchChange(newPageNumber)
await nextTick()
// Loop through all elements on the page
for (let i = 0; i < document.querySelectorAll('div').length; i++) {
const el = document.querySelectorAll('div')[i]
if (el === searchWrapper.value) {
console.log(`Element name (IS searchWrapper): ${el.nodeName}, id: ${i}`)
}
if (el.scrollHeight > el.clientHeight && el.scrollTop > 0) {
console.log(`Element name: ${el.nodeName}, id: ${i}, scroll: ${el.scrollTop}`)
}
}
console.log(document.querySelectorAll('div'))
console.log(searchWrapper.value)
console.log(searchWrapper.value.scrollTop)
searchWrapper.value.scrollTo({ top: 0, behavior: 'smooth' })
}
Expand Down
2 changes: 1 addition & 1 deletion theseus_gui/src/pages/instance/Mods.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
<AnimatedLogo v-if="mod.updating" class="btn icon-only updating-indicator"></AnimatedLogo>
<Button v-else :disabled="!mod.outdated" icon-only @click="updateProject(mod)">
<UpdatedIcon v-if="mod.outdated" v-tooltip="'Update project'" />
<CheckIcon v-else v-tooltip="'Fully updated'" />
<CheckIcon v-else v-tooltip="'Updated'" />
</Button>
<input
id="switch-1"
Expand Down
19 changes: 8 additions & 11 deletions theseus_gui/src/pages/project/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
:install="install"
:installed="installed"
:installing="installing"
:installedVersion="installedVersion"
:installed-version="installedVersion"
/>
</div>
</div>
Expand Down Expand Up @@ -261,7 +261,6 @@ import {
add_project_from_version as installMod,
check_installed,
get as getInstance,
get_projects_metadata as getMetadatas,
remove_project,
} from '@/helpers/profile'
import dayjs from 'dayjs'
Expand Down Expand Up @@ -294,7 +293,6 @@ const members = shallowRef([])
const dependencies = shallowRef([])
const categories = shallowRef([])
const instance = ref(null)
const metadatas = ref(null)
const installed = ref(false)
const installedVersion = ref(null)
Expand All @@ -307,24 +305,23 @@ async function fetchProjectData() {
dependencies.value,
categories.value,
instance.value,
metadatas.value,
] = await Promise.all([
useFetch(`https://api.modrinth.com/v2/project/${route.params.id}`, 'project'),
useFetch(`https://api.modrinth.com/v2/project/${route.params.id}/version`, 'project'),
useFetch(`https://api.modrinth.com/v2/project/${route.params.id}/members`, 'project'),
useFetch(`https://api.modrinth.com/v2/project/${route.params.id}/dependencies`, 'project'),
get_categories().catch(handleError),
route.query.i ? getInstance(route.query.i, true).catch(handleError) : Promise.resolve(),
route.query.i ? getMetadatas(route.query.i).catch(handleError) : Promise.resolve(),
route.query.i ? getInstance(route.query.i, false).catch(handleError) : Promise.resolve(),
])
installed.value =
instance.value?.path &&
(await check_installed(instance.value.path, data.value.id).catch(handleError))
breadcrumbs.setName('Project', data.value.title)
installedVersion.value = instance.value
? Object.values(metadatas.value).find((p) => p?.version?.project_id === data.value.id)?.version
?.id
? Object.values(instance.value.projects).find(
(p) => p?.metadata?.version?.project_id === data.value.id
)?.metadata?.version?.id
: null
}
Expand All @@ -348,17 +345,17 @@ const markInstalled = () => {
async function install(version) {
installing.value = true
let queuedVersionData
metadatas.value = await getMetadatas(instance.value.path).catch(handleError)
instance.value = await getInstance(instance.value.path, false).catch(handleError)
if (installed.value) {
await remove_project(
instance.value.path,
Object.entries(metadatas.value)
Object.entries(instance.value.projects)
.map(([key, value]) => ({
key,
value,
}))
.find((p) => p.value.version?.project_id === data.value.id).key
.find((p) => p.value.metadata?.version?.project_id === data.value.id).key
)
}
Expand Down

0 comments on commit 94f8856

Please sign in to comment.