Skip to content

Commit

Permalink
feat: support persist for battle-of-giants
Browse files Browse the repository at this point in the history
Signed-off-by: Dup4 <lyuzhi.pan@gmail.com>
  • Loading branch information
Dup4 committed Dec 28, 2023
1 parent 854f21b commit e1ecf52
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/apps/board/src/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ declare global {
const useRefHistory: typeof import('@vueuse/core')['useRefHistory']
const useResizeObserver: typeof import('@vueuse/core')['useResizeObserver']
const useRoute: typeof import('vue-router')['useRoute']
const useRouteQueryForBattleOfGiants: typeof import('./composables/query')['useRouteQueryForBattleOfGiants']
const useRouter: typeof import('vue-router')['useRouter']
const useScreenOrientation: typeof import('@vueuse/core')['useScreenOrientation']
const useScreenSafeArea: typeof import('@vueuse/core')['useScreenSafeArea']
Expand Down Expand Up @@ -562,6 +563,7 @@ declare module 'vue' {
readonly useRefHistory: UnwrapRef<typeof import('@vueuse/core')['useRefHistory']>
readonly useResizeObserver: UnwrapRef<typeof import('@vueuse/core')['useResizeObserver']>
readonly useRoute: UnwrapRef<typeof import('vue-router')['useRoute']>
readonly useRouteQueryForBattleOfGiants: UnwrapRef<typeof import('./composables/query')['useRouteQueryForBattleOfGiants']>
readonly useRouter: UnwrapRef<typeof import('vue-router')['useRouter']>
readonly useScreenOrientation: UnwrapRef<typeof import('@vueuse/core')['useScreenOrientation']>
readonly useScreenSafeArea: UnwrapRef<typeof import('@vueuse/core')['useScreenSafeArea']>
Expand Down Expand Up @@ -869,6 +871,7 @@ declare module '@vue/runtime-core' {
readonly useRefHistory: UnwrapRef<typeof import('@vueuse/core')['useRefHistory']>
readonly useResizeObserver: UnwrapRef<typeof import('@vueuse/core')['useResizeObserver']>
readonly useRoute: UnwrapRef<typeof import('vue-router')['useRoute']>
readonly useRouteQueryForBattleOfGiants: UnwrapRef<typeof import('./composables/query')['useRouteQueryForBattleOfGiants']>
readonly useRouter: UnwrapRef<typeof import('vue-router')['useRouter']>
readonly useScreenOrientation: UnwrapRef<typeof import('@vueuse/core')['useScreenOrientation']>
readonly useScreenSafeArea: UnwrapRef<typeof import('@vueuse/core')['useScreenSafeArea']>
Expand Down
10 changes: 10 additions & 0 deletions packages/apps/board/src/components/board/Board.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ const enableAutoScroll = ref(false);
}
})();
(() => {
const routeQueryForBattleOfGiants = useRouteQueryForBattleOfGiants();
if (
routeQueryForBattleOfGiants.value !== null
&& routeQueryForBattleOfGiants.value !== undefined
) {
rankOptions.value.battleOfGiants.FromBase64(routeQueryForBattleOfGiants.value);
}
})();
const currentGroup = ref("all");
function onChangeCurrentGroup(nextGroup: string) {
if (nextGroup === rankOptions.value.group) {
Expand Down
11 changes: 9 additions & 2 deletions packages/apps/board/src/components/board/OptionsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,19 @@ function onCancel() {
const localStorageKeyForFilterOrganizations = getLocalStorageKeyForFilterOrganizations();
const localStorageKeyForFilterTeams = getLocalStorageKeyForFilterTeams();
const routeQueryForBattleOfGiants = useRouteQueryForBattleOfGiants();
function onConfirm() {
// can't use useStorage, maybe it's a bug
localStorage.setItem(localStorageKeyForFilterOrganizations, JSON.stringify(orgSelectedItems.value));
localStorage.setItem(localStorageKeyForFilterTeams, JSON.stringify(teamsSelectedItems.value));
if (rankOptions.value.battleOfGiants.persist) {
routeQueryForBattleOfGiants.value = rankOptions.value.battleOfGiants.ToBase64();
} else {
routeQueryForBattleOfGiants.value = undefined as unknown as string;
}
isHidden.value = true;
}
</script>
Expand Down Expand Up @@ -218,7 +225,7 @@ function onConfirm() {
v-model="rankOptions.battleOfGiants.equalTeams"
/>

<!-- <span
<span
text-sm font-medium
text-gray-900 dark:text-gray-300
>
Expand All @@ -227,7 +234,7 @@ function onConfirm() {

<TheCheckbox
v-model="rankOptions.battleOfGiants.persist"
/> -->
/>

<span
text-sm font-medium
Expand Down
8 changes: 8 additions & 0 deletions packages/apps/board/src/composables/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ export function getDataSourceUrl() {
{ transform: String },
);
}

export function useRouteQueryForBattleOfGiants() {
return useRouteQuery(
"battle-of-giants",
"",
{ transform: String },
);
}
1 change: 1 addition & 0 deletions packages/libs/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"chroma-js": "^2.4.2",
"color-diff": "^1.4.0",
"dayjs": "^1.11.8",
"js-base64": "^3.7.5",
"lodash": "^4.17.21",
"ordinal": "^1.0.3",
"papaparse": "^5.4.1",
Expand Down
41 changes: 41 additions & 0 deletions packages/libs/core/src/battle-of-giants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Base64 } from "js-base64";
import { type SelectOptionItem } from "./basic-types";
import type { Team } from "./team";

Expand Down Expand Up @@ -89,6 +90,15 @@ export class Giants {

return [two(h), two(m)].join(":");
}

toJSON() {
return {
type: this.type,
name: this.name,
filterOrganizations: this.filterOrganizations,
filterTeams: this.filterTeams,
};
}
}

export class BattleOfGiants {
Expand All @@ -109,4 +119,35 @@ export class BattleOfGiants {
this.blueTeam = new Giants(GiantsType.BLUE);
this.redTeam = new Giants(GiantsType.RED);
}

ToBase64(): string {
return Base64.encode(JSON.stringify(this));
}

FromBase64(base64: string) {
if (base64.length === 0) {
return;
}

if (Base64.isValid(base64) === false) {
return;
}

const j = JSON.parse(Base64.decode(base64));

this.enable = j.enable;
this.topX = j.topX;
this.equalTeams = j.equalTeams;
this.persist = j.persist;

this.blueTeam = new Giants(GiantsType.BLUE);
this.blueTeam.name = j.blueTeam.name;
this.blueTeam.setFilterOrganizations(j.blueTeam.filterOrganizations);
this.blueTeam.setFilterTeams(j.blueTeam.filterTeams);

this.redTeam = new Giants(GiantsType.RED);
this.redTeam.name = j.redTeam.name;
this.redTeam.setFilterOrganizations(j.redTeam.filterOrganizations);
this.redTeam.setFilterTeams(j.redTeam.filterTeams);
}
}
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e1ecf52

Please sign in to comment.