Skip to content

Commit

Permalink
make user profile stats work
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikue committed Apr 26, 2024
1 parent 8c680c0 commit 2d689e6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
13 changes: 11 additions & 2 deletions src/components/ExtensionBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import VolumesOverlay from "components/VolumesOverlay.vue";
import UserProfile from "components/UserProfile.vue";
import DropdownList from "components/DropdownList.vue";
import {loginSession, useLoginStore, useVolumesStore} from '../store';
import {loginSession, useLoginStore, useVolumesStore, useStatsStore, useChatStore} from '../store';
import {connectChatSocket} from '../chat_socket';
import logoGemImage from '../images/pyr icon.svg';
import logoTextImage from '../images/pyr wordmark.svg';
Expand All @@ -13,11 +14,19 @@ function encodeSVG(svg: string) {
return "data:image/svg+xml;charset=utf-8," + encodeURIComponent(svg);
}
function initLoginServices() {
const {loopUpdateLeaderboard} = useStatsStore();
loopUpdateLeaderboard();
connectChatSocket();
const {joinChat} = useChatStore();
joinChat();
}
const login = useLoginStore();
window.addEventListener("middleauthlogin", () => {
login.update();
});
login.update();
login.update().then(() => initLoginServices());
const validLogins = computed(() => login.sessions.filter(x => x.status === undefined));
const invalidLogins = computed(() => login.sessions.filter(x => x.status !== undefined));
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type Config = {
volumes_url?: string,
leaderboard_url: string,
user_stats_url: string,
//user_stats_url: string,
chat_url: string,
/*brainMeshURL: string,
brainMeshOpacityDark: number,
Expand Down
8 changes: 1 addition & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {createPinia} from 'pinia';
import 'neuroglancer/ui/default_viewer.css';

import App from 'components/App.vue';
import {useLayersStore, useStatsStore, useChatStore} from 'src/store';
import {connectChatSocket} from 'src/chat_socket';
import {useLayersStore} from 'src/store';
import {setupDefaultViewer} from 'third_party/neuroglancer/ui/default_viewer_setup';

function mergeTopBars() {
Expand All @@ -26,9 +25,4 @@ window.addEventListener('DOMContentLoaded', () => {
const viewer = setupDefaultViewer();
initializeWithViewer(viewer);
mergeTopBars();
const {loopUpdateLeaderboard} = useStatsStore();
loopUpdateLeaderboard();
connectChatSocket();
const {joinChat} = useChatStore();
joinChat();
});
22 changes: 13 additions & 9 deletions src/store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Ref, ref, reactive, nextTick} from 'vue';
import {defineStore} from 'pinia';
import {defineStore, storeToRefs} from 'pinia';

import {Viewer} from 'neuroglancer/viewer';
import {defaultCredentialsManager} from 'neuroglancer/credentials_provider/default_manager';
Expand Down Expand Up @@ -229,9 +229,7 @@ export const useStatsStore = defineStore('stats', () => {
let userInfo: UserInfo = reactive({editsToday: 0, editsThisWeek: 0, editsAllTime: 0});
let cellsSubmitted: Ref<number> = ref(0);

const {sessions} = useLoginStore();
const loggedInUser = sessions[0];

const {sessions} = storeToRefs(useLoginStore());
function setLeaderboardTimespan(ts: LeaderboardTimespan) {
leaderboardTimespan = ts;
}
Expand Down Expand Up @@ -266,12 +264,17 @@ export const useStatsStore = defineStore('stats', () => {

async function updateUserInfo() {
if (!CONFIG) return;
const loggedInUser = sessions.value[0];
if (!loggedInUser) return;
const userID = loggedInUser.id;
const url = CONFIG.leaderboard_url + '/userInfo?userID=' + userID;
fetch(url).then(result => result.json()).then(async(json) => { userInfo = json; });
const statsURL = CONFIG.user_stats_url + '&user_id=' + userID;
fetch(statsURL).then(result => result.json()).then(async(json) => { cellsSubmitted = json["cells_submitted_all_time"]; });
fetch(url).then(result => result.json()).then(async(json) => {
userInfo.editsAllTime = json.editsAllTime;
userInfo.editsThisWeek = json.editsThisWeek;
userInfo.editsToday = json.editsToday;
});
//const statsURL = CONFIG.user_stats_url + '&user_id=' + userID;
//fetch(statsURL).then(result => result.json()).then(async(json) => { cellsSubmitted = json["cells_submitted_all_time"]; });
}

return {leaderboardLoaded, leaderboardEntries, userInfo, cellsSubmitted,
Expand Down Expand Up @@ -305,10 +308,10 @@ export const useChatStore = defineStore('chat', () => {
let chatMessages: ChatMessage[] = reactive([]);
let unreadMessages: Ref<boolean> = ref(false);

const {sessions} = useLoginStore();
const loggedInUser = sessions[0];
const {sessions} = storeToRefs(useLoginStore());

function sendJoinMessage(ws: ReconnectingWebSocket) {
const loggedInUser = sessions.value[0];
const joinMessage = JSON.stringify({
type: joinedChat ? 'rejoin' : 'join',
name: loggedInUser ? loggedInUser.name : 'Guest'
Expand All @@ -318,6 +321,7 @@ export const useChatStore = defineStore('chat', () => {
}

function sendMessage(message: string) {
const loggedInUser = sessions.value[0];
const now = new Date();
const messageObj = {
name: loggedInUser ? loggedInUser.name : 'Guest',
Expand Down

0 comments on commit 2d689e6

Please sign in to comment.