Rename GraphsPreferencesOut to simply GraphsPreferences

This commit is contained in:
Henrik Giesel 2021-01-22 19:22:36 +01:00
parent 17ebb69151
commit de71123ab4
7 changed files with 22 additions and 22 deletions

View file

@ -256,12 +256,12 @@ def graph_data() -> bytes:
return aqt.mw.col.backend.graphs(search=args["search"], days=args["days"])
def graph_preferences() -> bytes:
return aqt.mw.col.backend.graphs_preferences()
def graph_preferences() -> pb.GraphsPreferences:
return aqt.mw.col.backend.get_graphs_preferences()
def set_graph_preferences() -> None:
input = pb.GraphsPreferencesOut()
input = pb.GraphsPreferences()
input.ParseFromString(request.data)
aqt.mw.col.backend.set_graphs_preferences(input=input)

View file

@ -116,8 +116,8 @@ service BackendService {
rpc CardStats(CardID) returns (String);
rpc Graphs(GraphsIn) returns (GraphsOut);
rpc GraphsPreferences(Empty) returns (GraphsPreferencesOut);
rpc SetGraphsPreferences(GraphsPreferencesOut) returns (Empty);
rpc GetGraphsPreferences(Empty) returns (GraphsPreferences);
rpc SetGraphsPreferences(GraphsPreferences) returns (Empty);
// media
@ -1094,7 +1094,7 @@ message GraphsOut {
int32 local_offset_secs = 7;
}
message GraphsPreferencesOut {
message GraphsPreferences {
enum Weekday {
SUNDAY = 0;
MONDAY = 1;

View file

@ -676,11 +676,11 @@ impl BackendService for Backend {
self.with_col(|col| col.graph_data_for_search(&input.search, input.days))
}
fn graphs_preferences(&self, _input: pb::Empty) -> BackendResult<pb::GraphsPreferencesOut> {
self.with_col(|col| col.graphs_preferences())
fn get_graphs_preferences(&self, _input: pb::Empty) -> BackendResult<pb::GraphsPreferences> {
self.with_col(|col| col.get_graphs_preferences())
}
fn set_graphs_preferences(&self, input: pb::GraphsPreferencesOut) -> BackendResult<Empty> {
fn set_graphs_preferences(&self, input: pb::GraphsPreferences) -> BackendResult<Empty> {
self.with_col(|col| col.set_graphs_preferences(input))
.map(Into::into)
}

View file

@ -47,14 +47,14 @@ impl Collection {
})
}
pub(crate) fn graphs_preferences(&self) -> Result<pb::GraphsPreferencesOut> {
Ok(pb::GraphsPreferencesOut {
pub(crate) fn get_graphs_preferences(&self) -> Result<pb::GraphsPreferences> {
Ok(pb::GraphsPreferences {
calendar_first_day_of_week: self.get_first_day_of_week() as i32,
card_counts_separate_inactive: self.get_card_counts_separate_inactive(),
})
}
pub(crate) fn set_graphs_preferences(&self, prefs: pb::GraphsPreferencesOut) -> Result<()> {
pub(crate) fn set_graphs_preferences(&self, prefs: pb::GraphsPreferences) -> Result<()> {
self.set_first_day_of_week(match prefs.calendar_first_day_of_week {
1 => Weekday::Monday,
5 => Weekday::Friday,

View file

@ -41,8 +41,8 @@ interface DayDatum {
date: Date;
}
type WeekdayType = pb.BackendProto.GraphsPreferencesOut.Weekday;
const Weekday = pb.BackendProto.GraphsPreferencesOut.Weekday; /* enum */
type WeekdayType = pb.BackendProto.GraphsPreferences.Weekday;
const Weekday = pb.BackendProto.GraphsPreferences.Weekday; /* enum */
export function gatherData(
data: pb.BackendProto.GraphsOut,

View file

@ -20,8 +20,8 @@ export async function getGraphData(
);
}
export async function getGraphPreferences(): Promise<pb.BackendProto.GraphsPreferencesOut> {
return pb.BackendProto.GraphsPreferencesOut.decode(
export async function getGraphPreferences(): Promise<pb.BackendProto.GraphsPreferences> {
return pb.BackendProto.GraphsPreferences.decode(
await postRequest("/_anki/graphPreferences", JSON.stringify({}))
);
}
@ -30,7 +30,7 @@ export async function setGraphPreferences(prefs: PreferencePayload): Promise<voi
return (async (): Promise<void> => {
await postRequest(
"/_anki/setGraphPreferences",
pb.BackendProto.GraphsPreferencesOut.encode(prefs).finish()
pb.BackendProto.GraphsPreferences.encode(prefs).finish()
);
})();
}

View file

@ -8,16 +8,16 @@ export interface CustomStore<T> extends Writable<T> {
}
export type PreferenceStore = {
[K in keyof Omit<pb.BackendProto.GraphsPreferencesOut, "toJSON">]: CustomStore<
pb.BackendProto.GraphsPreferencesOut[K]
[K in keyof Omit<pb.BackendProto.GraphsPreferences, "toJSON">]: CustomStore<
pb.BackendProto.GraphsPreferences[K]
>;
};
export type PreferencePayload = {
[K in keyof Omit<
pb.BackendProto.GraphsPreferencesOut,
pb.BackendProto.GraphsPreferences,
"toJSON"
>]: pb.BackendProto.GraphsPreferencesOut[K];
>]: pb.BackendProto.GraphsPreferences[K];
};
function createPreference<T>(
@ -40,7 +40,7 @@ function createPreference<T>(
}
function preparePreferences(
graphsPreferences: pb.BackendProto.GraphsPreferencesOut
graphsPreferences: pb.BackendProto.GraphsPreferences
): PreferenceStore {
const preferences: Partial<PreferenceStore> = {};